2
int main()
{
    int x = 3, z ;
    z = x / + + x ;
    printf ("x = %dz = %d", x , z );
    return 0;
}

I thought the output will be x=4 z=0 or x=4 z=1. But I'm getting x=3 z=1.

nhahtdh
  • 54,546
  • 15
  • 119
  • 154
user2713461
  • 377
  • 2
  • 5
  • 16

2 Answers2

3

Try removing spaces between ++ (increment operator). Use ++x or ++ x. Compiler may be interpreting it as +(+x), i.e. unary + operator.

Don't You Worry Child
  • 5,896
  • 2
  • 24
  • 50
1

remove spaces in between two pluses

z = x / ++ x ;  //will gives z value as 1 always  

//except when x=-1 (Floating point exception )

this Might have Undefined Behaviour because Lack of sequence point.

rather than above if you could try like this.

int x = 3, z=3;
printf ("x = %dz = %d", x , z );

z/=(++x); // z/=++x; is also same.  
printf ("x = %dz = %d", x , z );
Gangadhar
  • 9,880
  • 3
  • 29
  • 50