What is the output of the code written in C? void main() { int k = 8, v = 8,…

2021

What is the output of the code written in C? void main() { int k = 8, v = 8, i; i = k / ++v; printf("%d\n", i); }

  1. A.

    0

  2. B.

    1

  3. C.

    0.8

  4. D.

    Error

Attempted by 1005 students.

Show answer & explanation

Correct answer: A

Step 1: The variable v is initialized to 8.

Step 2: The expression ++v is a pre-increment, so v is incremented to 9 before the division.

Step 3: The division k / ++v becomes 8 / 9.

Step 4: Since both operands are integers, integer division is performed, resulting in 0.

Step 5: The printf statement prints the integer value 0.

Explore the full course: Up Lt Grade Assistant Teacher 2025