Assigment Operators & Expressions – C Programming Interview Questions and Answers

Question 1
What is the output of this C code?
#include 
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
Question 2
What is the output of this C code?
#include 
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
Question 3
What is the output of this C code?
#include 
void main()
{
char a = 'a';
int x = (a % 10)++;
printf("%d\n", x);
}
A
6
B
Junk value
C
Compile time error
D
7
Question 4
What is the output of this C code?
#include 
void main()
{
1 < 2 ? return 1: return 2;
}
A
returns 1
B
returns 2
C
Varies
D
Compile time error
Question 5
What is the output of this C code?
#include 
void main()
{
unsigned int x = -5;
printf("%d", x);
}
A
Run time error
B
Aries
C
-5
D
5
Question 6
What is the output of this C code?
#include 
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
Question 7
What is the output of this C code?
#include 
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
Question 8
What is the output of this C code?
#include 
int main()
{
int x = 1, y = 0;
x &&= y;
printf("%d\n", x);
}
A
Compile time error
B
1
C
0
D
Undefined behaviour
Question 9
What is the type of the below assignment expression if x is of type float, y is of type int?  y = x + y;
A
int
B
float
C
There is no type for an assignment expression
D
double
Question 10
What is the value of the below assignment expression  (x = foo())!= 1 considering foo() returns 2
A
2
B
True
C
1
D
0
Question 11
Operation “a = a * b + a” can also be written as:
A
a *= b + 1;
B
(c = a * b)!=(a = c + a);
C
a = (b + 1)* a;
D
All of the mentioned
Question 12
for c = 2, value of c after c <<= 1;
A
c = 1;
B
c = 2;
C
c = 3;
D
c = 4;
Question 13
What is the output of this C code?
#include 
int main()
{
int a = 1, b = 2;
a += b -= a;
printf("%d %d", a, b);
}
A
1 1
B
1 2
C
2 1
D
2 2
Question 14
What is the output of this C code?
#include 
int main()
{
int a = 4, n, i, result = 0;
scanf("%d", n);
for (i = 0;i < n; i++)
result += a;
}
A
Addition of a and n.
B
Subtraction of a and n.
C
Multiplication of a and n.
D
Division of a and n.
Question 15
Which of the following is an invalid assignment operator?
A
a %= 10;
B
a /= 10;
C
a |= 10;
D
None of the mentioned




Check Your Answers:

  1.  A
  2.  B
  3.  C
  4.  D
  5.  C
  6.  D
  7.  A
  8.  A
  9.  A
10.  A
11.  D
12.  D
13.  C
14.  C
15.  D











SHARE

Unknown

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment