C programming language quirks

In my UG days, I spent a lot of time with the C programming language. Had forgotten most of it.

But now (Feb 2023) I'm a TA for a lab course using C. Noting down stuff that I came across again..


1

#include<stdio.h>

int main() {
    int a=3, b;
    b = sizeof(a=10);
    printf("a=%d, b=%d\n", a, b);
    // a=3, b=4

    // Value of b is compiler dependent though.

    return 0;
}

(Thanks to Kevin for telling me this.)

2

Multiple sequence points => undefined behaviour.

#include<stdio.h>

int main() {
    int a=3;
    printf("%d\n", a++ + ++a);
    // 8

    // Needn't be so though. It's undefined behaviour.

    return 0; 
}

Evaluation could be one of the following:

(Thanks to Kevin for reminding me about this.)