C Variables and Datatypes-1
1. How many keywords are there in C Language ?
a) 30
b) 22
c) 32
d) 36
Answer: C
There are total 32 keywords in C Language. Keywords are predefined, reserved words in C language that have special meanings to the compiler.
2. Which of the following cannot be a variable name in C?
a) volatile
b) area
c) mega
d) number
Answer: A
volatile is a keyword in C language.
3. Identify wrong C keyword below
a) auto, double, int, struct
b) break, else, long, switch
c) case, enum, register, typedef
d) char, extern, intern, return
Answer: D
'intern' is not a keyword. Remaining are all valid keywords.
4. What is the output of this program?
#include <stdio.h>
int main() {
int x = 10;
float x = 10.0;
printf("%d",x);
return 0;
}
a) 10.1
b) Compilations Error
c) 10
d) 10
Answer: B
Since the variable x is defined both as integer and as float, it results in an error.
5. Find a correct C Keyword below.
a) breaker
b) default
c) shorter
d) go to
Answer: B
default is the correct keyword used in switch case.
6. Find a correct C Keyword below.
a) work
b) permanent
c) constant
d) case
Answer: D
case is the correct keyword used in switch case.
7. Comment on the output of this C code?
a) The compiler will flag an error
b) Program will compile and print the output 5
c) Program will compile and print the ASCII value of 5
d) Program will compile and print FAIL for 5 times
Answer: D
The ASCII value of 5 is 53, the char type-casted integeral value of 5 is 5 only.
The output of the above program is
FAIL
FAIL
FAIL
FAIL
FAIL
8. Which of the following is true for variable names in C?
a) Variable names cannot start with a digit
d) Variable can be of any length
b) They can contain alphanumeric characters as well as special characters
c) Reserved Word can be used as variable name
Answer: A
Variable names cannot start with a digit in C Programming language.
9. What is the output of this program?
#include <stdio.h>
int main() {
int i;
for(i = 0; i < 5; i++) {
int a = i;
}
printf("%d",a);
return 0;
}
a) Syntax error in declaration of a
b) No errors, program will show the output 5
c) Redeclaration of a in same scope throws error
d) a is out of scope when printf is called
Answer: A
The output of this program is the syntax error in declaration of variable a because variable a is declared inside the for loop.
10. What is the output of this program?
#include <stdio.h>
int main() {
int p, q, r, s;
p = 1;
q = 2;
r = p, q;
s = (p, q);
printf("p = %d q = %d",p ,q);
return 0;
}
a) p=1 q=1
b) p=1 q=2
c) p=2 q=2
d) Invalid Syntax
Answer: B
The comma operator evaluates both of its operands and produces the value of the second. It also has lower precedence than assignment. Hence r = p, q is equivalent to r = p, while s = (p, q) is equivalent to s = q.