Define control variable within for statement - C Statement

C examples for Statement:for

Description

Define control variable within for statement

Demo Code

#include <stdio.h>

int main() {/*  w w  w.  j  a  v  a 2  s . c  o  m*/

   int n = 0;
   printf("   Initially, n = %d at %p\n", n, &n);
   for (n = 1; n < 3; n++)
      printf("      loop 1: n = %d at %p\n", n, &n);

   printf("After loop 1, n = %d at %p\n", n, &n);

   for (n = 1; n < 3; n++) {
      printf(" loop 2 index n = %d at %p\n", n, &n);

      printf("      loop 2: n = %d at %p\n", n, &n);
      n++;
   }
   printf("After loop 2, n = %d at %p\n", n, &n);

   return 0;
}

Result


Related Tutorials