Log In Register

Units


Variable Names - Questions and Answers

 

Practice these Variable Names  under C Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on Variable Names for following purpose.


– Anyone who is wishing to increase their perfect knowledge of Variable Names of C Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge C Programming specifically Variable Names .
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on Variable Names under C Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of  Variable Names topic of C Programming:

 

1.

What is the problem in following variable declaration?
float 3Bedroom-Hall-Kitchen?;

Answer: Option D

Explanation:

A variable name cannot start with an integer, along with that the C compiler
interprets the ‘-‘ and ‘?’ as a minus operator and a question mark operator respectively.

2.

Which of the following is true for variable names in C?

Answer: Option D

Explanation:

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

3.

Which of the following is not a valid variable name declaration?

Answer: Option D

Explanation:

4.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int y = 10000;
  5.         int y = 34;
  6.         printf("Hello World! %d\n", y);
  7.         return 0;
  8.     }

Answer: Option D

Explanation:

Since y is already defined, redefining it results in an error.
Output:
$ cc pgm2.c
pgm2.c: In function ‘main’:
pgm2.c:5: error: redefinition of ‘y’
pgm2.c:4: note: previous definition of ‘y’ was here

5.

Which of the following is not a valid C variable name?

Answer: Option A

Explanation:

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

6.

All keywords in C are in

Answer: Option C

Explanation:

7.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         printf("Hello World! %d \n", x);
  5.         return 0;
  6.     }

Answer: Option B

Explanation:

It results in an error since x is used without declaring the variable x.
Output:
$ cc pgm1.c
pgm1.c: In function ‘main’:
pgm1.c:4: error: ‘x’ undeclared (first use in this function)
pgm1.c:4: error: (Each undeclared identifier is reported only once
pgm1.c:4: error: for each function it appears in.)

8.

What will happen if the below program is executed?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int main = 3;
  5.         printf("%d", main);
  6.         return 0;
  7.     }

Answer: Option B

Explanation:

A C program can have same function name and same variable name.
$ cc pgm3.c
$ a.out
3

9.

Comment on the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int ThisIsVariableName = 12;
  5.         int ThisIsVariablename = 14;
  6.         printf("%d", ThisIsVariablename);
  7.         return 0;
  8.     }

Answer: Option C

Explanation:

Variable names ThisIsVariablename and ThisIsVariableName are both distinct as C is case sensitive.
Output:
$ cc pgm4.c
$ a.out
14

10.

C99 standard guarantess uniqueness of _____ characters for external names.

Answer: Option D

Explanation:

ISO C99 compiler may consider only first 31 characters for external
variables having 31 characters due to which it may not be unique.

11.

C99 standard guarantees uniqueness of ____ characters for internal names.

Answer: Option C

Explanation:

ISO C99 compiler may consider only first 63 characters for internal.

12.

Which of the following cannot be a variable name in C?

Answer: Option D

Explanation:

volatile is C keyword.

13.

Variable name resolving (number of significant characters for uniqueness of variable) depends on

Answer: Option B

Explanation:

It depends on the standard to which compiler and linkers are adhering to.

14.

Variable names beginning with underscore is not encouraged. Why?

Answer: Option B

Explanation:

15.

Which is valid C expression?

Answer: Option C

Explanation:

Space, comma and $ cannot be used in a variable name.