3

According to this question "What does an assignment return?" and What is the result of an assignment expression in C?

Sandro Munda and Ahmed Salah write

  1. Assign the value 2 to i
  2. Evaluate the i variable and display it

So, based on the statement above, I expect the following code will output

1
1
1

However, it outputs

1
0
1

Code:

#include <stdio.h>
void func(int a){}
int main()
{
    int var;
    //////////////////////
    var=0;
    func(var=1);
    printf("%d\n",var);
    /////////////////////
    var=0;
    sizeof(var=1);
    printf("%d\n",var);
    /////////////////////
    var=0;
    printf("",var=1);
    printf("%d\n",var);

   return 0;
}

My question is what makes this difference? Why does assignment in "sizeof()" not work as two other counterpart?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user3094631
  • 425
  • 3
  • 13

0 Answers0