• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Numeric Literals that include a comma

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Numeric literals that include a comma, for example,
int x = 25,343; // Decimal
int y = 0x1,1; // Octal

The above lines doesn't compile because of the comma.

But,
int x = 0xa,b // Octal

doesnot give a compile time error. Why?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

int x = 0xa,b; // Octal



This is equivalent to:
 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ashwatha K:
Hi,

Numeric literals that include a comma, for example,
int x = 25,343; // Decimal
int y = 0x1,1; // Octal

The above lines doesn't compile because of the comma.

But,
int x = 0xa,b // Octal

doesnot give a compile time error. Why?


-----------------------------

In the line, int x= 25,343;
compiler assumes like this, x = 25 and assumes 343 as another var. which is not a legal variable name. same for the next line. learn about the legal var. names.
var. names can only start with _ or $ or any alphabet.but not number.
 
Get me the mayor's office! I need to tell him about this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic