Monday 16 October 2017

Declaring vs defining variables in c





As I know this is a
declaration:



int
i;


and this is a
definition:



int i =
10;



May be
I am wrong I don't argue.



The
question is
Does the compiler set aside memory for the declared (but not
defined) variables?


itemprop="text">
class="normal">Answer





Does the
compiler set aside memory for the declared (but not defined)

variables?





No,
compiler just take a note of this variable name and type. No memory is allocated for
declaration.



int i; can
behave as definition if i is used (not optimized out) and href="http://ideone.com/nNy1fu" rel="nofollow">no other definition of
i is present in any other compilation unit and storage will be
reserved for it. (because storage is reserved for definitions)



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...