C - What is the output: two variables declared in the first loop control condition

Question

What is the output from the following code

for(int i = 1, j = 2 ; i <= 5 ; ++i, j = j + 2)
  printf("  %5d", i*j);


Click to view the answer

The output produced by this fragment will be the values 2, 8, 18, 32, and 50 on a single line.

Demo

#include <stdio.h>

int main(void)
{
    for(int i = 1, j = 2 ; i <= 5 ; ++i, j = j + 2){
       printf("  %5d", i*j);
    }//from ww  w  .ja  va2  s .c om
    
    return 0;
}

Result

Related Quiz