Discussion in "General help Guidance and Discussion" started by    mohansaini    Nov 29, 2014.
Sat Nov 29 2014, 03:09 pm
#1
int main()
                 {
                      int arr[0];
                      arr[0]=1;
                        printf("size=%d val=%d\n",sizeof(arr),arr[0]);
                        return 0;
                   }


output is 0,1. why its size is zero if there is no memory allocated then how it can store a value.
Tue Dec 02 2014, 03:13 am
#2


why its size is zero if there is no memory allocated then
how it can store a value.

mohansaini


"int arr[0]; " creates a pointer to an integer, that is, a location in
memory where an integer can be stored.

The complier It does not actually have to allocate any storage.
The statement is suspicious, but not illegal.

"arr[0]=1;" places '1' at that location.
The location physically exists, but very likely is in use for
something else.
 ajay_bhargav like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am
utaletxcyw
Wed Apr 17 2024, 10:21 am
Anthonyvab
Wed Apr 17 2024, 08:48 am
RobertCix
Wed Apr 17 2024, 06:46 am