Compilers Questions and Answers – Implementation of Increment and Decrement – 1

This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses 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
View Answer

Answer: a
Explanation: 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?

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

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

Answer: b
Explanation: a=2 cause it has been incremented.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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
View Answer

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

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

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

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

Answer: c
Explanation: 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
View Answer

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

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

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

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

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

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

#‎include‬ <stdio.h>
int main()
{
    int x=4, y, z;
    y = --x;
    z = x--;
    printf("%d, %d, %d\n", x, y, z);
    return 0;
}

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

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

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

#include <stdio.h>
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
View Answer

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

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

#include <stdio.h>
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
View Answer

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

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

#include <stdio.h>
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
View Answer

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

Sanfoundry Global Education & Learning Series – Compilers.

To practice all areas of Compilers, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.