Why can't we increment the value of i in sizeof like this:-
Code:sizeof(i++)
Printable View
Why can't we increment the value of i in sizeof like this:-
Code:sizeof(i++)
The sizeof() is a compile-time constant value depending on the argument. The argument to sizeof() must be a known type at compile time. The "i++" is not a type, it's an executable statement.Quote:
Originally Posted by sunnypalsingh
Regards,
Paul McKenzie
This expression is valid (and returns the size of the return value of the expression i++), but it does not increment i.
In fact, most expressions can be used with sizeof operator, but sizeof operator never evaluates the expression!
Quote:
-1- The sizeof operator yields the number of bytes in the object representation of its operand. The operand is either an expression, which is not evaluated, or a parenthesized type-id. The sizeof operator shall not be applied to an expression that has function or incomplete type, or to an enumeration type before all its enumerators have been declared, or to the parenthesized name of such types, or to an lvalue that designates a bit-field. sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1; the result of sizeof applied to any other fundamental type (basic.fundamental) is implementation-defined. [Note: in particular, sizeof(bool) and sizeof(wchar_t) are implementation-defined.*
Thanx a lot
According to the C99 standard..isn't this statement becomes wrong.....Since C99 introduced VLAs (variable length arrays) so the sizeof operator had to be modified to support VLAs.Quote:
Originally Posted by Paul McKenzie
// EDIT : What follows is the original post, which is false!Quote:
Originally Posted by sunnypalsingh
No, variable length arrays are pointers in C99.
That is, sizeof(VLA)==sizeof(Type *)==4 for a 32 bits compiler!
okie.....got it
Sorry, i made an error:Quote:
Originally Posted by sunnypalsingh
That code:
Outputs 4*the_number_entered!Code:#include <stdio.h>
int main()
{
unsigned n;
scanf("%u",&n);
int VLA[n];
printf("%u",sizeof(VLA));
}
So, VLA are really some different thing!
You know what...i am actually feeling great....Quote:
Originally Posted by SuperKoko