1,037 views
0 votes
0 votes
Say I declare an array like

int abc ;

int arr[abc] ;

printf("%d",sizeof(arr));

Now this abc holds some garbage value so then how come the size of the array is negative value , does it means that the array arr is not allocated any memory space ?

1 Answer

1 votes
1 votes

I executed same on unix machine and output is :1504931616 . I am using 64bit unix O.S , gcc compile to run the program .

U are getting negative it could be due randomness of the garbage values. That's why it's called garbage as there is no such pattern which is followed in displaying values.

And moreover negative does not mean that address space is not allocated , negative may mean that the way variable are stored .They could be stored in unsinged form.

Related questions

1 votes
1 votes
1 answer
1
radha gogia asked Jul 29, 2015
670 views
#include<stdio.h int main(){ int test=0; float a = 3424.34; printf("hello \n %d",(test? a: 3)); return 0; }It is giving output as hello 0 ,I am unable to understand the l...
0 votes
0 votes
1 answer
2
Priyankamishra asked Jun 10, 2018
3,831 views
Array follows static memory allocation then why it gives garbage value in case of uninitialized array .and it gives zero when the array is partially initialized?
1 votes
1 votes
2 answers
3