C Questions and Answers Part-1

1. Which of the following is not a valid C variable name?
a) float rate;
b) int variable_count;
c) int number;
d) int $main;

Answer: d
Explanation: Since only underscore and no other special character is allowed in a variable name, it results in an error.

2. Which of the following is not a valid variable name declaration?
a) #define PI 3.14
b) float PI = 3.14;
c) double PI = 3.14;
d) int PI = 3.14;

Answer: a
Explanation: #define PI 3.14 is a macro preprocessor, it is a textual substitution.

3. All keywords in C are in ____________
a) LowerCase letters
b) CamelCase letters
c) UpperCase letters
d) None of the above

Answer: a
Explanation: LowerCase letters

4. Why do variable names beginning with the underscore is not encouraged?
a) To avoid conflicts since assemblers and loaders use such names
b) It is not standardized
c) To avoid conflicts since library routines use such names
d) To avoid conflicts with environment variables of an operating system

Answer: c
Explanation: To avoid conflicts since library routines use such names

5. C99 standard guarantees uniqueness of ___________ characters for external names.
a) 6
b) 12
c) 14
d) 31

Answer: d
Explanation: ISO C99 compiler may consider only first 31 characters for external names.

6. Which of the following is not a valid variable name declaration?
a) int _a3;
b) int 3_a;
c) int a_3;
d) int _3a

Answer: b
Explanation: Variable name cannot start with a digit.

7. Which is valid C expression?
a) int my_num = 100,000;
b) int my_num = 100000;
c) int $my_num = 10000;
d) int my num = 1000;

Answer: b
Explanation: Space, comma and $ cannot be used in a variable name.

8. Which of the following is true for variable names in C?
a) It is not an error to declare a variable to be one of the keywords(like goto, static)
b) They can contain alphanumeric characters as well as special characters
c) Variable names cannot start with a digit
d) Variable can be of any length

Answer: c
Explanation: According to the syntax for C variable name, it cannot start with a digit.

9. Which of the following is not a valid variable name declaration?
a) int __a3;
b) int __A3;
c) int __3a;
d) None of the above

Answer: d
Explanation: None of the above

10. Variable name resolution (number of significant characters for the uniqueness of variable) depends on ___________
a) Compiler and linker implementations
b) C language
c) Assemblers and loaders implementations
d) None of the above

Answer: a
Explanation: It depends on the standard to which compiler and linkers are adhering.