Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22001

Why in C does the function sizeof() output the size of right most operand when more than one operands are passed separated by comma?

$
0
0

I have the following code in C:

#include <stdio.h> void main() {    printf("%d %d\n",sizeof(5),sizeof(5,5));       printf("%d %d\n",sizeof(5),sizeof(5.0,5));     printf("%d %d\n",sizeof(5),sizeof(5,5.0)); }

And I get the output:

4 4

4 4

4 8

I understand that sizeof(5) would return me the size of integer and sizeof(5.0) would return the size of a double, but why does it give the size of the rightmost operand in case more than one arguments are passed separated by comma? Why not the first argument or the collective size of all the arguments?

I am compiling online using OnlineGDB.com compiler for C.

Thanks for your help.


Viewing all articles
Browse latest Browse all 22001

Trending Articles