Please Turn On Java Script To Access This Site.

C Institute | Questions


Previous Topic : Variable name and scope 1Next Topic : Variable name and scope 3

This section on C interview questions, tricky questions, and puzzles focuses on “Variable naming convention”. One shall practice these questions and puzzles to improve their C programming skills needed for various interviews (campus interviews, walk-in interviews, viva exams and company interviews), placements, entrance exams and other competitive exams. These programming questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate, engineering student, bca student, mca student, mcs students or an experienced IT professional. Here is a listing of C questions and puzzles on “variable names” along with answers and/or explanations.

Q1: Which is valid C expression?
a)  int your_salary = 5,50,000;
b)  int your salary = -5000;
c)  int your_salary = 550000;
d)  int your-salary = 550000;
Correct Answer : c
Explanation : Comma cannot be used in numbers.
Any special symbol other than underscore (_) can not be used in identifier.


Q2: Which is not a valid c expression?
a)  int a=3.4;
b)  float Integer=10;
c)  char x=65;
d)  None of the above
Correct Answer : d
Explanation : All the declarations satisfies the rules for constructing variables.


Q3: Which is not a valid c variable declaration?
a)  int x=2.5;
b)  double float=3.4;
c)  float extern x=90;
d)  char gen-of;
Correct Answer : d


Q4: Which is a valid variable declaration?
a)  int Printf=2;
b)  int if=20;
c)  float my-salary=2000;
d)  double salary=1.234.455;
Correct Answer : a


Q5: Which is invalid variable name?
a)  hi$world
b)  two_number
c)  thirdVariable
d)  None of the above
Correct Answer : a
Explanation : $ sign can not be used in variable name.


Q6: Which is a valid variable name?
a)  total%
b)  1st
c)  Int
d)  name of student
Correct Answer : c
Explanation : Int is not a keyword because of capital letter I. So we can use Int as an identifier.


Q7: Which is not a invalid variable name?
a)  g.s.t.
b)  temp_in_Degree
c)  salary?
d)  __1234abc?
Correct Answer : b
Explanation : We can use alphabets and underscore in variable name.


Q8: Which is not a valid variable name?
a)  while
b)  WhilE
c)  Integer
d)  friend
Correct Answer : a
Explanation : while is a keyword, so it can not be used as variable name.


Q9: What can not be used in variable name?
a)  Space
b)  Underscore
c)  Digit
d)  Upper case alphabet
Correct Answer : a
Explanation : Space is not allowed in variable names.


Q10: Variable can not be started with?
a)  Alphabet
b)  Underscore
c)  Capital alphabet
d)  Digit
Correct Answer : d
Explanation : Variable name can contain digit but can not be started by digit.


Previous Topic : Variable name and scope 1Next Topic : Variable name and scope 3