IQOD #8

Posts 1–15 of 23 · Page 1 of 2
IQOD #8
Consider the following code snippet
Code:
void main()
{
   int i = 3;
   int j = sizeof(++i+ ++i);
   printf("i=%d j=%d", i,j);
}
what is the output it generates?
i=5 j=9 , that is not the output.
but i don't understand
"i="%d j=%d"
is printf the same as cout?
Yes it's the 'C' equivalent..

printf("%d",x); // print 'x' as a number
printf("%s",y); // print 'y' as a string etc

basically the same as:

cout << x;

as far as the numbers you came up with: <!-- they are incorrect -->
int j = sizeof(++i+ ++i); isnt this the same as j= (++i+ ++i) what is (3+1)+ (4+1)=9 or is sizeof something i dont know yet

my mistake could also be in ++i+ because the ++i and the + aren't separated it is increased again
Check IQOD #7 for a description on what sizeof is/does
the extra " was my typo so I removed it
Quote Originally Posted by B1ackAnge1 View Post
Code:
void main()
{
   int i = 3;
   int j = sizeof(++i+ ++i);
   printf("i="%d j=%d", i,j);
}

Errors:
printf has a " after i=
sizeof returns the size of whatever variable you stuff into it, which in the case of i is 4.

i think that i is not increased because its done in sizeof so it wouldnt be seen as something it had to increase right?
so i think the output would be i=3 j=4
It outputs i=3 j=4
I think
What does i+ do?
Hmmm no one has answered this yet? i=5 j=9

Correct? incorrect? Tell me. The anticipation is killing me! D:


i think that i is not increased because its done in sizeof so it wouldnt be seen as something it had to increase right?
And nope HD. I'm pretty dam sure it would increase. Just like in that recursion problem that gave me hell
Quote Originally Posted by BooYa View Post
What does i+ do?
same thing 1+1 does, adds them together.
Quote Originally Posted by why06 View Post
same thing 1+1 does, adds them together.
Ah confusing, i thought it needed a space for that

i = 3 and j = 9
Code:
void main()
{
   int i = 3;
   int j = sizeof(++i+ ++i);
I don't understand is it saying
i = 3 and
j = i + i
j = 6

:S:S:S:S:S:S:S:S:S:S:S:S:S:S:S:S
i = 3 j = 8

lala's theorie
sizeof does mean that i isn't actually changing but is suggesting that it is changed so it would be j= (3+1) + (3+1) <---this is still 3 because it hasn't changed. if this is wrong the answer is i = 3 j = 9




legendary ++i means i is increased by 1
Posts 1–15 of 23 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us