Which statement(s) is/are true about formation of identifier in C? I. It consist of alphabets, digits and underscore. II. An identifier can start with an underscore.
Both I and II
Identifiers in the C programming language are names given to variables, functions, arrays, structures, unions, labels, etc. They are fundamental building blocks when writing C code. There are specific rules that must be followed when creating these identifiers to ensure they are valid.
Let's break down the rules for forming identifiers and evaluate the given statements.
The general rules for forming identifiers in C are:
A-Z and a-z), digits (0-9), and the underscore character (_).myvariable is different from MyVariable).This statement claims that a C identifier is made up of only alphabets, digits, and the underscore character. Based on the rules mentioned above, this is true. These are the only characters permitted within a C identifier.
This statement claims that a C identifier can begin with an underscore. According to the rules, the first character of an identifier must be a letter or an underscore. Therefore, starting an identifier with an underscore is indeed allowed in C.
Both Statement I and Statement II accurately describe valid aspects of forming identifiers in the C programming language.
Thus, both statements are true.
| Rule Aspect | Description | Valid Example | Invalid Example |
|---|---|---|---|
| Allowed Characters | Alphabets (a-z, A-Z), Digits (0-9), Underscore (_) | my_var1 |
my-var (contains '-') |
| Starting Character | Must be a letter or an underscore | _count, data |
1variable (starts with digit) |
| Case Sensitivity | C is case-sensitive | Var and var are different |
N/A |
| Keywords | Cannot be keywords | myint |
int (is a keyword) |
While starting an identifier with an underscore is syntactically correct, it is a common convention in C programming to avoid using identifiers that start with an underscore, especially followed by another underscore or an uppercase letter. Such names are often reserved for internal use by the C standard library and system headers. Using them might lead to name conflicts.
The length of an identifier is technically unlimited by the C standard, but compilers might have limitations on the number of significant characters. However, for practical purposes, keeping identifier names reasonably short and descriptive is good practice.
In object-oriented programming, which keyword ensures that a member variable belongs to the class itself rather than to any specific object, thereby allowing all instances to share a single copy of that variable?
The three basic structure types used to write the algorithm for a program are sequence, selection and repetition. Which of the following is NOT an advantage of using only these structures when writing the algorithm for a program?
What is the output of the code written in C?
void main()
{
printf("%d",7%-3);
printf("%d",-7%3);
}
Which of the following statement(s) is/are true about pre-processor in C/C++?
I. To replace each #include directive with the contents of the designated file.
II. To replace each escape sequence with designated character.
III. To process macro definitions and expand macro calls.
______ converts a source code to object code.