• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Numeric Literals that include a comma

 
Anitha Lingam
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int x = 0xa,b; // Octal


This is equivalent to:
 
Deepa Korecherla
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic