Vemula Sreenath

Saturday, 10 November 2012

Increment and Decrement Operators and Nesting



1.Increment and Decrement Operators
Consider
 i=5;
 j=i++ + i++ + ++i + ++i;
 here on printing j, value is 28
Consider
 i=5;
 j=++i + ++i + ++i + ++i
 here on printing j is 36

 From this we can observe that just count the number of prefix increment and
 then based on that i value multiply the number of i's present in expression
 i.e. in first one,
  there are two ++i's. So, j=4*(i+2)=4*7=28


2.Nesting of Blocks
Consider
 int i=5;
 {
  int i=10;
  printf("%d",i);
 }
 printf("%d",i);

 The variables declared with in block is local to that block and memory frees as soon as control comes out of that block unless it is specified by storage class static or extern.
 there fore output of above program is 10 5

No comments:

Post a Comment