Reputation: 17
#include<stdio.h>
int main()
{
int i=3,val;
val=sizeof (f(i))+ +f(i=1)+ +f(i-1);
printf("%d%d",val,i);
getch();
return 0;
}
int f(int num)
{
return num*5;
}
The compiler compiles the program and gives the output 7 1 ..what do the " + +" mean???
Upvotes: 0
Views: 50
Reputation: 234645
First note that sizeof
is compile-time evaluable so the first term in val
will be sizeof(int)
: int
being the return type of f
.
The value of the entire expression that you want to assign to val
is undefined since +
as a binary and unary operator is not sequenced. In essence you don't know if i = 1
will happen before or after the evaluation of i - 1
.
As for your specifics, a + + b
is evaluated as a + (+b)
. +b
is simply a unary plus (almost a no-op, but does do some subtle type coercion), the other +
is the addition operator taking two arguments.
Upvotes: 2