give the o/p for the following code ....also explain how...
int i=10,j;
j=sizeof(++i + ++i);
printf("%d %d",i,j);
Printable View
give the o/p for the following code ....also explain how...
int i=10,j;
j=sizeof(++i + ++i);
printf("%d %d",i,j);
Integer size is 2 bytes. so j carring value 2 and i carrying value 12.
the result is i=12 and j=2
[QUOTE=Sriroshika;30572]Integer size is 2 bytes. so j carring value 2 and i carrying value 12.[/QUOTE]
thanks for the answer...but i carries the same 10 and j carries 2...
test the code please and let me know y the value of i remains the same..
[QUOTE=jaiprabuk;30617]thanks for the answer...but i carries the same 10 and j carries 2...
test the code please and let me know y the value of i remains the same..[/QUOTE]
how i carry the value 12 please give the detial answer
It depends on size of integer.
/* Assuming size of int as 32 bits */
10 4
Hi,
A principal use of the sizeof operator is in communication with routines such as storage allocators. A storage-allocation function might accept a size (in bytes)and allocate and return a pointer to void.
Another use of the sizeof operator is to compute the number of elements in an array:
sizeof array / sizeof array[0]
I have not come across any use as below
[QUOTE=jaiprabuk;30570]give the o/p for the following code ....also explain how...
int i=10,j;
j=sizeof(++i + ++i);
printf("%d %d",i,j);[/QUOTE]
however
generic output is
10 and X(X=One word Length)
10 and 2(on a 16 bit )
10 and 4(on a 32 bit )
10 and 8(on a 64 bit )
Here as we may expect the sizeof has an expression in it and we assume it to be evaluated. But this is not the case as the ISO C standard define the sizeof opeator having constraint as
[B][I]"The sizeof operator shall not be applied to an expression that has function type or an incomplete type, to the parenthesized name of such a type, or to an expression that designates a bit-field member."[/I][/B]
The operand of a sizeof operator is usually not evaluated .
I have referred Committee Draft — Septermber 7, 2007 ISO/IEC 9899:TC3
Regards,
younus saleem :)
i=12
j=2(dos)
j=4(windows)
Yes,I would agree to Younus.[B]sizeof()[/B] doesn't allow any operation inside it.That's why the o/p should be 10 and 4 or 2 depending on the configuration of the user's m/c.
4, 8
sizeof operator gives the no of bits it can occupy.