Ask Question
21 September, 18:20

What is the output of the following code segment?

n = 1;

for (; n < = 5; )

cout << n << ' ';

n++;

1. 1 2 3 4 5

2. 1 1 1 ... and on forever

3. 2 3 4 5 6

4. 1 2 3 4

5. 2 3 4 5

+5
Answers (1)
  1. 21 September, 22:08
    0
    Answer

    1 2 3 4 5

    Explanation:

    initialize the value of n with 1

    then, for loop is executed until the condition is true.

    so, it check the condition 1<=5, condition true, code is executed and print 1

    and n become 2.

    again check condition 2<=5 condition true, code is executed and print 2

    and n become 3.

    and so on ...

    it print 1 2 3 4 5 after that check condition 6<=5 condition false, it terminate from loop.

    Therefore, the answer is 1 2 3 4 5
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “What is the output of the following code segment? n = 1; for (; n < = 5; ) cout ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers