Loops


  1. In the program given below, point out the error, if any, in the for loop.

    #include <studio.h>
    int main()
    {
    int i = 1;
    for (;;)
    {
    printf("%d\n", i++);
    if (i > 10)
    break;
    }
    return 0;
    }









  1. View Hint View Answer Discuss in Forum

    No error

    Correct Option: D

    No error


  1. Which of the following is the correct output for the program given below ?

    #include <studio.h>
    int main()
    {
    char i = 0;
    for (i<=5 && i>= -1; ++i; i>0)
    printf ("%d\n",i);
    printf ("%\n");
    return 0;
    }









  1. View Hint View Answer Discuss in Forum

    1 2 3 ..... 126 127 -

    Correct Option: A

    1 2 3 ..... 126 127 -128 - 127 .... -2 -1



  1. Which of the following statement is correct about the program given below?


    #include <studio.h>
    int main ()
    {
    int i = 0;
    for(i = 0; i <= 127; printf ("%d", i++))
    ;
    printf ("\n");
    return 0;
    }









  1. View Hint View Answer Discuss in Forum

    The program would output 0 1 2 ..... 126 127.

    Correct Option: B

    The program would output 0 1 2 ..... 126 127.


  1. Which of the following is the correct output for the program given below?

    #include <studio.h>
    int main ( )
    {
    char j = 1;
    while (j <= 255)
    {
    printf("%d",j );
    j = j + 1;
    }
    printf ( "\n");
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    1 2 3 .. 127 -128 -127 -126 .. -2 -1 0 1 2 .. 127 -128 -127 .. infinite times

    Correct Option: E

    1 2 3 .. 127 -128 -127 -126 .. -2 -1 0 1 2 .. 127 -128 -127 .. infinite times



  1. Which of the following is the correct output for the program given below?
    #include <stdio.h>
    int main ( )
    {
    int k = 5;
    while(k-->=0) printf("%d",k);
    i = 5;
    printf ("\n");
    while(k-->=0) printf("%d",k);
    printf ("\n");
    while(k-->=0) printf("%d",k);
    printf("\n");
    return 0;
    }









  1. View Hint View Answer Discuss in Forum

    Only first and 2nd loop will be executing here

    Correct Option: A

    Only first and 2nd loop will be executing here
    So output will be.
    4 3 2 1 0 -1
    4 3 2 1 0 -1