in Programming in C
247 views
1 vote
1 vote
In what cases does an uninitialized array have values = 0 and for which cases does it have values = garbage values. How to differentiate?
in Programming in C
247 views

1 Answer

1 vote
1 vote

If the array is globally defined or partially initialized then it contain 0 


                       for eg : int a[5]={1,2}

                       so in this case if you try to access a[3] then it will return 0

                           

If array is locally defined in a particular function but not initialized then it contain garbage value  

                          for eg: int a[5];

                   if you try to access the  a[3] it will return garbage value

 

                       

I hope this will clear your doubt
 

by

Related questions