简体   繁体   中英

evaluation of expression which is used with sizeof

Is there any expression that would be evaluated as operand of a sizeof. I have come to know in case of variable length operand with sizeof, the expression would be evaluated. But I cant make 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 observed from output expression a[1]++ is not evaluating. how to make an example??

Your array is not a variable-length array. A variable length array is an array whose size is not a constant expression. For example, data is a variable-length array in the following:

int i = 10;
char data[i];

To see an example of a code that has sizeof evaluate 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;
}

It prints:

i: 41
array size: 41
i now: 42

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM