C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - General Questions (Q.No. 3)
3.
Which of the following special symbol allowed in a variable name?
* (asterisk)
| (pipeline)
- (hyphen)
_ (underscore)
Answer: Option
Explanation:

Variable names in C are made up of letters (upper and lower case) and digits. The underscore character ("_") is also permitted. Names must not begin with a digit.

Examples of valid (but not very descriptive) C variable names:
=> foo
=> Bar
=> BAZ
=> foo_bar
=> _foo42
=> _
=> QuUx

Discussion:
42 comments Page 1 of 5.

Thiru said:   2 decades ago
Names must not begin with a digit.??Is this is right?

Rajan said:   1 decade ago
Yes Thiru. Variables should start only with an alphabet or _ (underscore).

Examples:

Valid statements:

int a;
int area2;
int _Sum;
int A_Sum;
int _23area;

Invalid statements:

int 23area;
int @ss;

Sureshkumar said:   1 decade ago
Where to use underscore operator? can you give me the merits and demerits?

Prathyusha said:   1 decade ago
AS FAR AS I KNOW , VARIABLE DECLARATION RULES:
1]VARIABLE NAME MUST START WITH A LETTER OR SPECIAL CHARACTER UNDERSCORE(_)IS ALSO ALLOWED AS FIRST CHARACTER.
2]OTHER THAN UNDERSCORE NO OTHER SYMBOL IS ALLOWED IN VARIABLE NAME.
3]VARIABLE NAME CAN BE 32 CHARACTERS(THIS IS SYSTEM DEPENDENT)
4]VARIABLES MUST NOT CONTAIN ANY KEYWORDS.

CORRECT ME IF I AM WRONG!...

Kanakam vinay kumar said:   1 decade ago
You are Correct prathyu.

Sudi said:   1 decade ago
Is the declaration int area_2; correct?

Subhalaxmi said:   1 decade ago
I can not understand the question clearly? can you give full explanation?

Keshav said:   1 decade ago
Why only _ underscore is allowed?

Sunil said:   1 decade ago
As only underscore is predefined to used as variable name.

Ravi said:   1 decade ago
It is necessary to declare variable in this format.


Post your comments here:

Your comments will be displayed after verification.