give the o/p for the following code ....also explain how...
int i=10,j;
j=sizeof(++i + ++i);
printf("%d %d",i,j);
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.
Last edited by Sriroshika; 05-27-2008 at 03:01 AM.
the result is i=12 and j=2
Last edited by Sriroshika; 05-27-2008 at 03:03 AM.
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
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
"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."
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.sizeof() 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.