Quantcast
Channel: User Alex Lop. - Stack Overflow
Viewing all articles
Browse latest Browse all 39

Answer by Alex Lop. for for loop: make increment and accessing in one loop

$
0
0

A for loop consists of 4 parts:

  1. Initialisation
  2. Condition
  3. Body code
  4. Action

Example:

 for (initialisation; condition; action) {     Body code }

The execution order is as I enumerated it above.

In your example,

for (int i = 0; i++< 10; a[i-1]){    printf("%i:%i\n");}
  1. Initialisation - i = 1
  2. Condition - i++< 10; --> 0 < 10 = true, i = 1
  3. Body code - printf while i=1, a[0] is still uninitialised!
  4. Action - a[i-1] = i, a[0] = 1 (only now a[0] gets initialised!

Viewing all articles
Browse latest Browse all 39

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>