Ask Question
20 March, 20:58

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

+1
Answers (1)
  1. 20 March, 21:38
    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?
Get an answer to your question ✅ “What is the output of the following code segment? n = 1; for (; n < = 5; ) cout ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers