I am trying the following code :
int main() {
int x[10] ;
int a[] = {1,2,3,4,5} ;
int n ;
int b[n] ;
//int c[] ; gives compilation error
cout<<sizeof(x)<<endl ; //prints 40
cout<<sizeof(a)<<endl ; //prints 20
cout<<sizeof(b)<<endl ; //prints 4
}
Now my question is what exactly happens when I define b
.
I have tried to read answers to similar questions but I did not get a satisfactory reply.
Because arrays are created statically, so there size must be given at the time of declaring them. Then why is declaration of b
valid. Does the sizeof(b)
indicate that this just treated as a int pointer