This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Assignment Operators & Expressions – 1”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. What will be the output of the following C code?
#include <stdio.h>
void main()
{
int x = 0;
if (x = 0)
printf("Its zero\n");
else
printf("Its not zero\n");
}
a) Its not zero
b) Its zero
c) Run time error
d) None
View Answer
Explanation: In the above C code, we assign a zero value to the variable x. In the if condition, we are reassigning a value of zero to x. Remember, we are “NOT” comparing its values to zero (you can see that it is a single ‘=’ sign, it’s not a double ‘==’ sign). Hence, the if-condition becomes false and the printf() function of the else condition will be executed which will display “Its not zero”.
2. What will be the output of the following C code?
#include <stdio.h>
void main()
{
int k = 8;
int x = 0 == 1 && k++;
printf("%d%d\n", x, k);
}
a) 0 9
b) 0 8
c) 1 8
d) 1 9
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
void main()
{
char a = 'a';
int x = (a % 10)++;
printf("%d\n", x);
}
a) 6
b) Junk value
c) Compile time error
d) 7
View Answer
Explanation: None.
4. What will be the output of the following C code snippet?
#include <stdio.h>
void main()
{
1 < 2 ? return 1: return 2;
}
a) returns 1
b) returns 2
c) Varies
d) Compile time error
View Answer
Explanation: None.
5. What will be the output of the following C code snippet?
#include <stdio.h>
void main()
{
unsigned int x = -5;
printf("%d", x);
}
a) Run time error
b) Aries
c) -5
d) 5
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 2, y = 1;
x *= x + y;
printf("%d\n", x);
return 0;
}
a) 5
b) 6
c) Undefined behaviour
d) Compile time error
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 2, y = 2;
x /= x / y;
printf("%d\n", x);
return 0;
}
a) 2
b) 1
c) 0.5
d) Undefined behaviour
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 1, y = 0;
x &&= y;
printf("%d\n", x);
}
a) Compile time error
b) 1
c) 0
d) Undefined behaviour
View Answer
Explanation: None.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Practice Computer Science MCQs
- Watch Advanced C Programming Videos
- Check Computer Science Books
- Practice BCA MCQs
- Apply for C Internship