NO

Author Topic: little puzzle  (Read 3988 times)

czerny

  • Guest
little puzzle
« 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;
}

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: little puzzle
« Reply #1 on: May 06, 2014, 07:03:32 PM »
sizeof(n++); is a cheat >:(

Snowman

  • Guest
Re: little puzzle
« Reply #2 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.
« Last Edit: March 19, 2015, 10:28:03 AM by Snowman »