Evaluate C for-loop execution count

Quick Overview

This question evaluates understanding of C expression evaluation and control-flow semantics, focusing on how assignment expressions interact with loop conditions and variable updates.

Evaluate C for-loop execution count

Company: Bitkernel

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Online Assessment

In C, variables `m` and `n` are both of type `int`. Consider the following code: ```c int m, n; for (m = 0, n = -1; n = 0; m++, n++) n++; ``` In standard C semantics (where `=` is assignment, not comparison), how many times does the loop body (`n++` inside the loop) execute? Options: - A. The loop body executes 0 times - B. The loop body executes 1 time - C. The loop is infinite - D. There is a runtime error

Quick Answer: This question evaluates understanding of C expression evaluation and control-flow semantics, focusing on how assignment expressions interact with loop conditions and variable updates.

|Home/Software Engineering Fundamentals/Bitkernel
Bitkernel logo
Bitkernel
Oct 24, 2025
mediumSoftware EngineerOnline AssessmentSoftware Engineering Fundamentals
2
0

In C, variables m and n are both of type int. Consider the following code:

int m, n;
for (m = 0, n = -1; n = 0; m++, n++)
    n++;

In standard C semantics (where = is assignment, not comparison), how many times does the loop body (n++ inside the loop) execute?

Options:

  • A. The loop body executes 0 times
  • B. The loop body executes 1 time
  • C. The loop is infinite
  • D. There is a runtime error
Loading comments...