Evaluating an expression that is used with sizeof

Is there any expression that will be evaluated as a sizeof operand. I found out in the case of an operand of variable length with sizeof, the expression will be evaluated. But I can’t give an example, I wrote the code below,

int a[]={1,2,3};
printf("%d",sizeof(a[1]++));
printf("%d\n",a[1]);

but here I noticed that the expression output is a[1]++not evaluated. how to make an example?

+5
source share
1 answer

Your array is not a variable length array. An array of variable length is an array whose size is not a constant expression. For example, it datais an array of variable length in the following:

int i = 10;
char data[i];

To see an example of the code that has sizeofevaluates its operand, try something like this:

#include <stdio.h>

int main(void)
{
    int i = 41;
    printf("i: %d\n", i);
    printf("array size: %zu\n", sizeof (char[i++]));
    printf("i now: %d\n", i);
    return 0;
}

He prints:

i: 41
array size: 41
i now: 42
+6

All Articles