250+ TOP MCQs on Implementation of Increment and Decrement Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Implementation of Increment and Decrement – 1”.
1. What value does the variable b have after ALL of the code executes?

int a;
int b;
a=1;
b=a++;

a) 1
b) 2
c) 3
d) unknown/undefined

Answer: a
Clarification: b will be one because when value of ais 1 it is stored.

2. What value does the variable a have after ALL of the code above executes?

int a;
int b;
a=1;
b=a++;

a) 1
b) 2
c) 3
d) unknown/undefined

Answer: b
Clarification: a=2 cause it has been incremented.

3. What value does the variable z have after ALL of the code above executes?

int x;
int y;
int z;
x=3;
y=4;
z = ++x * y++;

a) 9
b) 12
c) 16
d) 20

Answer: c
Clarification: z=4* 4
Hence the answer will be 16.

4. What value does the variable x have after ALL of the code above executes?

int x;
int y;
int z;
x=3;
y=4;
z = ++x * y++;

a) 2
b) 3
c) 4
d) unknown/undefined

Answer: c
Clarification: Finally the value of x is 4.

5. What value does the variable y have after ALL of the code above executes?

int x;
int y;
int z;
x=3;
y=4;
z = ++x * y++;

a) 4
b) 5
c) 6
d) unknown/undefined

Answer: b
Clarification: The value of y is increased by 1 and becomes 5.

6. What will be the output of the following program?

#include
int main()
{
    int i = 10;
    printf("%d", ++(-i));
    return 0;
}

a) 11
b) 10
c) -9
d) None of the mentioned

Answer: d
Clarification: The expression ++(-i) is not valid but –(++i) is valid.

7. What will be output of the following C code?

#‎include‬ 
int main()
{
    int x=4, y, z;
    y = --x;
    z = x--;
    printf("%d, %d, %dn", x, y, z);
    return 0;
}

a) 4,3,3
b) 3,3,3
c) 2,3,3
d) 4,4,3

Answer: c
Clarification: y = 3 and z= 3 but
x has decremented and become 2.

8. What will be output of the following C code?

#include 
main()
{
    int a=1, b=3;
    b= a++ + a++ + a++ + a++ + a++;
    printf("a=%d n b=%d",a,b); 
}

a) a = 6, b = 15
b) a = 1, b = 3
c) a = 1, b = 15
d) a = 2, b = 4

Answer: a
Clarification: B=1+2+3+4+5
B=15
But finally a=6.

9. What will be output of the following C code?

#include 
main()
{
    int a=9, b=9;
    a=b++;
    b=a++;
    b=++b; 
    printf("%d %d",a,b);
}

a) 9,9
b) 10,10
c) 9,10
d) 10,9

Answer: b
Clarification: A=9
B=9
B=10

10. What will be output of the following C code?

#include 
main()
{  
     int a,b;
     b = 10;
     a = ++b + ++b;
     printf("%d%d",a,b);
}

a) 24,12
b) 23,12
c) 23,10
d) 24,10

Answer: b
Clarification: A = 11+12
So a=23
B=12.

Leave a Reply

Your email address will not be published. Required fields are marked *