S
somenath
Hi All,
The sizeof operator is evaluated at compile time .so it can be treated
as compile time constant expression.
But when I compile the following program in g++
#include<stdio.h>
int main (void)
{
size_t size = sizeof(int);
int ar[size]={0} ;
return 0;
}
I get the error
$ g++ size_of_test.cpp
size_of_test.cpp: In function `int main()':
size_of_test.cpp:5: error: variable-sized object `ar' may not be
initialized
Why it says ar is variable sized object?
But when I compile the following program it compiles with out error
#include<stdio.h>
int main (void)
{
size_t size = sizeof(int);
int ar[4]={0} ;
return 0;
}
Regards,
Somenath
The sizeof operator is evaluated at compile time .so it can be treated
as compile time constant expression.
But when I compile the following program in g++
#include<stdio.h>
int main (void)
{
size_t size = sizeof(int);
int ar[size]={0} ;
return 0;
}
I get the error
$ g++ size_of_test.cpp
size_of_test.cpp: In function `int main()':
size_of_test.cpp:5: error: variable-sized object `ar' may not be
initialized
Why it says ar is variable sized object?
But when I compile the following program it compiles with out error
#include<stdio.h>
int main (void)
{
size_t size = sizeof(int);
int ar[4]={0} ;
return 0;
}
Regards,
Somenath