All Exams Test series for 1 year @ ₹349 only
Question

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.

The correct answer is

Both I and II

Understanding C Identifier Formation Rules

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.

Analyzing the Rules for C Identifiers

Let's break down the rules for forming identifiers and evaluate the given statements.

The general rules for forming identifiers in C are:

  • They can consist of letters (both uppercase and lowercase, A-Z and a-z), digits (0-9), and the underscore character (_).
  • The first character of an identifier must be either a letter or an underscore. It cannot be a digit.
  • C identifiers are case-sensitive (e.g., myvariable is different from MyVariable).
  • Keywords (reserved words with special meaning in C) cannot be used as identifiers.

Evaluation of Statement I: It consist of alphabets, digits and underscore.

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.

Evaluation of Statement II: An identifier can start with an underscore.

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.

Conclusion on C Identifier Statements

Both Statement I and Statement II accurately describe valid aspects of forming identifiers in the C programming language.

  • Statement I is true because identifiers are composed exclusively of letters, digits, and underscores.
  • Statement II is true because an identifier is permitted to start with an underscore.

Thus, both statements are true.

Revision Table: C Identifier Rules

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)

Additional Information on C Identifiers

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.

Was this answer helpful?

Important Questions from Programming in C

  1. 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?

  2. 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?

  3. What is the output of the code written in C?

    void main()

    {

    printf("%d",7%-3);

    printf("%d",-7%3);

    }

  4. 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.

  5. ______ converts a source code to object code.

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App