Wednesday, March 23, 2011

4.9 Initialization

  • In the absence of explicit initialization, external and static variables are initialized to zero; automatic and register variables have undefined/garbage initial values
  • For external and static variable, initializer must be a constant expression; initialization is done once, before the program begins execution
  • For automatic and register variable, initializer is not restricted to be a constant expression, it can be previously defined values or function calls; initialization is done each time the function or block is entered
  • An array may be initialized by following its declaration with a list of initializers enclosed in braces and separated by commas. ie:




  • When the size of array is omitted, compiler will compute the length by counting the initializers
  • For character arrays initialization, a string may be used instead of the braces and commas notation:


No comments:

Post a Comment