C Programming Multiple Choice Question - Variables And Datatypes
This section focuses on the "Variables And Datatypes" of the C programming. These Multiple Choice Questions (mcq) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. How many keywords are there in c ?
A. 31
B. 32
C. 64
D. 63
View Answer
Ans : B
Explanation: There are total 32 keywords in C.Keywords are those words whose meaning is already defined by Compiler.C Keywords are also called as Reserved words.
2. Which of the following is true for variable names in C?
A. Variable names cannot start with a digit
B. Variable can be of any length
C. They can contain alphanumeric characters as well as special characters
D. Reserved Word can be used as variable name
View Answer
Ans : A
Explanation: Variable names cannot start with a digit in C Programming language.
3. Which of the following cannot be a variable name in C?
A. TRUE
B. friend
C. export
D. volatile
View Answer
Ans : D
Explanation: volatile is C keyword.Volatile in C programming language signify that the compiler that the software in hand (the thread for the routine it’s compiling) doesn’t have exclusive control over the variable described as "volatile"
4. What is the output of this program?
void main()
{
int x = 10;
float x = 10;
printf("%d", x)
}
A. Compilations Error
B. 10
C. 10
D. 10.1
View Answer
Ans : A
Explanation: Since the variable x is defined both as integer and as float, it results in an error.
5. 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);
}
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
View Answer
Ans : A
Explanation: the output of this program is the Syntax error in declaration of variable a.
6. What is the output of this program?
#include <stdio.h>
int var = 20;
int main()
{
int var = var;
printf("%d ", var);
return 0;
}
A. Garbage Value
B. 20
C. Compiler Error
D. None of these
View Answer
Ans : A
Explanation: First var is declared, then value is assigned to it. As soon as var is declared as a local variable, it hides the global variable var.
7. What is the output of this program?
void main()
{
int p, q, r, s;
p = 1;
q = 2;
r = p, q;
s = (p, q);
printf("p=%d q=%d", p, q);
}
A. p=1 q=1
B. p=1 q=2
C. p=2 q=2
D. Invalid Syntex
View Answer
Ans : B
Explanation: 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.
8. What is the output of this program?
void main()
{
printf("%x",-1<<4);
}
A. fff0
B. fff1
C. fff2
D. fff3
View Answer
Ans : A
Explanation: -1 will be represented in binary form as:
1111 1111 1111 1111
Now -1<<4 means 1 is Shifted towards left by 4 positions, hence it becomes:
1111 1111 1111 0000 in hexadecimal form - fff0.
9. What is the output of this program?
#include <stdio.h>
void main()
{
int a=1, b=2, c=3, d;
d = (a=c, b+=a, c=a+b+c);
printf("%d %d %d %d", d, a, b, c);
}
A. 11 3 5 11
B. 11 1 5 11
C. 11 3 2 11
D. 11 3 3 11
View Answer
Ans : A
Explanation: For any comma separated expression the outcome is the right most part.
10. What is the output of this program?
void main()
{
int a, b = 5, c;
a = 5 * (b++);
c = 5 * (++b);
printf("%d %d",a,c);
}
A. 30 35
B. 30 30
C. 25 30
D. 25 35
View Answer
Ans : D
Explanation: a = 5 * 5 and b = 5 * 7
Also check :
Discussion