What will be the output of the following program : void main() { int i=5,j=5; i=i++i++*i++*i++; printf("i=%d ",i); j=++j++j*++j*++j; printf("j=%d",j); }

  1. Compile-Time Error

  2. i=1680 j=1680

  3. i=629 j=6561

  4. i=1681 j=3024


Correct Option: C

AI Explanation

To find the output of the program, let's go through each line of code:

void main() {
    int i=5,j=5;
    i=i++*i++*i++*i++;
    printf("i=%d ",i);
    j=++j*++j*++j*++j;
    printf("j=%d",j);
}

In this program, there are two variables i and j initialized with the value of 5.

  1. i=i++*i++*i++*i++;:

In this line, the value of i is incremented after each usage due to the post-increment operator i++. The expression i++ * i++ * i++ * i++ evaluates as follows:

  • i++ * i++ * i++ * i++ = 5 * 5 * 6 * 7 (since i is incremented after each usage)
  • 5 * 5 * 6 * 7 = 875

Therefore, the value of i becomes 875.

  1. printf("i=%d ",i);:

This line prints the value of i which is 875.

  1. j=++j*++j*++j*++j;:

In this line, the value of j is incremented before each usage due to the pre-increment operator ++j. The expression ++j * ++j * ++j * ++j evaluates as follows:

  • ++j * ++j * ++j * ++j = 6 * 7 * 8 * 9 (since j is incremented before each usage)
  • 6 * 7 * 8 * 9 = 3024

Therefore, the value of j becomes 3024.

  1. printf("j=%d",j);:

This line prints the value of j which is 3024.

Therefore, the output of the program is i=875 j=3024.

The correct answer is option D.

Find more quizzes: