I searched all over the net trying to find the reason behind why numbers are illegal as first characters in naming identifiers in C++, they say its illegal but they don't say why its illegal
Id be glad if someone could tell me why :) , just curious
I searched all over the net trying to find the reason behind why numbers are illegal as first characters in naming identifiers in C++, they say its illegal but they don't say why its illegal
Id be glad if someone could tell me why :) , just curious
It confuses the compiler.
The compiler will not be sure in all cases of your intentions.
Consider what this means now and what it would mean if variables could start with numerals.
#include <stdio.h>
int main(void)
{
long L1 = 111;
long L2 = 222;
L2 += L1 + 2L;
printf ("%ld", L2); // What value is printed??? (335)
return 0;
}
I searched all over the net trying to find the reason behind why numbers are illegal as first characters in naming identifiers in C++, they say its illegal but they don't say why its illegal
Leading digits would be confused with numeric literals. If you allow leading digits then that would require further restrictions on subsequent characters to ensure that the literal logic doesn't find a false positive, which complicates the language definition on top of complicating the compiler by making it do unnecessary validation.
thanks for the answers.. they really help :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.