Friday, March 04, 2005

Answer - for "Deceptions - C Quiz"

Though an automatic variable ('variable') is initialized, the initialization will not be accomplished because it is a sort of assignment operation and none of the operation is allowed in switch block(not in the case block). But when a static variable is initialized, it will be handled like a global variable(internally by the compiler) and hence the initialized value will be retained.

Replace the declaration of 'variable' with the below declaration
and see the result.

static int variable = 100;

** C certainly deceits us. **

No comments: