Here is a listing of C aptitude questions on “Assignment Operators & Expressions” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int x = 0;
-
if (x = 0)
-
printf("Its zeron");
-
else
-
printf("Its not zeron");
-
}
a) Its not zero
b) Its zero
c) Run time error
d) None
Answer: a
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int k = 8;
-
int x = 0 == 1 && k++;
-
printf("%d%dn", x, k);
-
}
a) 0 9
b) 0 8
c) 1 8
d) 1 9
Answer: b
Clarification: None.
3. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
char a = 'a';
-
int x = (a % 10)++;
-
printf("%dn", x);
-
}
a) 6
b) Junk value
c) Compile time error
d) 7
Answer: c
Clarification: None.
4. What will be the output of the following C code snippet?
-
#include
-
void main()
-
{
-
1 < 2 ? return 1: return 2;
-
}
a) returns 1
b) returns 2
c) Varies
d) Compile time error
Answer: d
Clarification: None.
5. What will be the output of the following C code snippet?
-
#include
-
void main()
-
{
-
unsigned int x = -5;
-
printf("%d", x);
-
}
a) Run time error
b) Aries
c) -5
d) 5
Answer: c
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int x = 2, y = 1;
-
x *= x + y;
-
printf("%dn", x);
-
return 0;
-
}
a) 5
b) 6
c) Undefined behaviour
d) Compile time error
Answer: b
Clarification: None.
7. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int x = 2, y = 2;
-
x /= x / y;
-
printf("%dn", x);
-
return 0;
-
}
a) 2
b) 1
c) 0.5
d) Undefined behaviour
Answer: a
Clarification: None.
8. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int x = 1, y = 0;
-
x &&= y;
-
printf("%dn", x);
-
}
a) Compile time error
b) 1
c) 0
d) Undefined behaviour
Answer: a
Clarification: None.