reopened by
585 views
1 votes
1 votes
#include<stdio.h>

int main()
{
    int x, y = 7;
    x = ++y + ++y + y--;
    printf("%d\n", x);
    return 0;
}

What is the output of this code snippet ?

A. 27

B. 26

C. 25

D. Compilation error

 

reopened by

2 Answers

–2 votes
–2 votes
Answer is A. 27
–3 votes
–3 votes
(y=7)

y--  -->y=7( y=y-1 will be perform at last)

++y -->y=y+1=7+1=8

(y=8, updated)

++y  -->y=8+1=9

(y=9, updated)

now x=y+y+y ----->(++y + ++y +y--)

x=9+9+9=27

now y=y-1 will be implemented

y=9-1=8

 

x=27,y=8

Related questions

0 votes
0 votes
2 answers
3