In C, apart from keywords, everything in the C program is treated as Identifier. Identifiers can be the names given to variables, constants, functions, and user-defined data. A variable name can consist of alphabets (upper case, lower case), numbers (0-9), and _ (underscore) character. But the name of any variable must not start with a number. Now we must have the answer that why can’t we name a variable starting with number. The following might be the reason for it. The compiler has 7 phase as follows:
Lexical Analysis Syntax Analysis Semantic Analysis Intermediate Code Generation Code Optimization Code Generation Symbol Table
Backtracking is avoided in the lexical analysis phase while compiling the piece of code. The variable like Apple;, the compiler will know it an identifier right away when it meets the letter ‘A’ character in the lexical analysis phase. However, a variable like 123apple; , compiler won’t be able to decide if its a number or identifier until it hits ‘a’ and it needs backtracking to go in the lexical analysis phase to identify that it is a variable. But it is not supported in the compiler.
When you’re parsing the token you only have to look at the first character to determine if it’s an identifier or literal and then send it to the correct function for processing. So that’s a performance optimization.
This article is contributed by Bishal Kumar Dubey. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Can we access global variable if there is a local variable with same name?
- Why does sizeof(x++) not increment x in C?
- Internal static variable vs. External static variable with Examples in C
- How to print a variable name in C?
- Write a C program that does not terminate when Ctrl+C is pressed
- C program that does not suspend when Ctrl+Z is pressed
- Why "&" is not used for strings in scanf() function?
- Why only subtraction of addresses allowed and not division/addition/multiplication
- Why strcpy and strncpy are not safe to use?
- Why is the size of an empty class not zero in C++?
- How to Count Variable Numbers of Arguments in C?
- Does C support function overloading?
- How does "void *" differ in C and C++?
- Does C++ compiler create default constructor when we write our own?
- How does free() know the size of memory to be deallocated?
- When does compiler create default and copy constructors in C++?
- Does overloading work with Inheritance?
- How does Duff's Device work?
- How does a C program executes?
- What does main() return in C and C++?
Improved By : om_mishra