Pelles C forum

General => Chit-Chat => Topic started by: czerny on May 06, 2014, 05:38:57 PM

Title: little puzzle
Post by: czerny on May 06, 2014, 05:38:57 PM
Try to guess first what is the output of this little proggi!
Code: [Select]
#define SIZE 5

int size(int s[SIZE])
{
return sizeof(s);
}

int main(int argc, char **argv)
{
int x[SIZE],k,n=SIZE;

k=size(x)+sizeof(n++);
printf("%d\n",k+n);
return 0;
}
Title: Re: little puzzle
Post by: jj2007 on May 06, 2014, 07:03:32 PM
sizeof(n++); is a cheat >:(
Title: Re: little puzzle
Post by: Snowman on March 19, 2015, 10:17:09 AM
Array to pointer decay caught me off guard. At least C++ has references to arrays.  ::)
Interesting how n remains 5 after sizeof(n++). I didn't know that (https://www.securecoding.cert.org/confluence/display/c/EXP44-C.+Do+not+rely+on+side+effects+in+operands+to+sizeof%2C+_Alignof%2C+or+_Generic).