0

The following code should give output as following:

i=4

j=10

k=3

The answer of i and j comes out correct in output but the value of k comes out to be 4. Why is this happening? I tried solving in every way I know but I get 3 every time!

Here is the code:

int i = 5;
int j = 10;
int k;
        
    
k = --i  +  i++  +  j--  -  i--  -  ++j;

cout<<"int i = "<<i<<endl; 
cout<<"int j = "<<j<<endl; 
cout<<"int k = "<<k<<endl; 

Here is its output on console:

int i = 4

int j = 10

int k = 4

Evg
  • 25,259
  • 5
  • 41
  • 83
Ibrahim
  • 59
  • 4

0 Answers0