Multiple choice

A C program contains following declaration: char text[80]; The for statement that permit a 60 character message and store it in array text is ________ text[i]=getchar();

  1. for(i=0;i<80;++i)

  2. for(i=0;i<=60;i++)

  3. for(i=1;i<60;i++)

  4. for(i=0;i<60;++i)

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

To read exactly 60 characters, the loop must run 60 times with index starting at 0 and going up to (but not including) 60. The condition 'i<60' achieves this - it runs for i=0,1,2,...,59, which is exactly 60 iterations. This stores characters at indices 0 through 59.