-- advertisement --

Loops

  1. Which keyword is used to exit a loop?
    1. goto
    2. exit
    3. break
    4. continue
  1. View Hint | View Answer | Workspace | Discuss In Forum | Report

    exit will terminate the program execution, goto is used to jump to another statement, continue is used to skip the immediate statement and start from the beginning.

    Correct Option: C

    break keyword is used to break from the loop.
    exit will terminate the program execution, goto is used to jump to another statement, continue is used to skip the immediate statement and start from the beginning.

    Report

  1. In the program given below, point out the error, if any, in the while loop.
    #include <studio.h>
    int main()
    {
    int k = 5;
    while ( )
    {
    printf("%d\n", k++);
    if (k >10)
    break;
    }
    return 0;
    }
    1. There should be a condition in the while loop.
    2. There should be at least a semicolon in the while( ).
    3. The while loop should be replaced by a for loop.
    4. No error
  1. View Hint | View Answer | Workspace | Discuss In Forum | Report

    The while() loop must have a conditional expression or it shows "Expression syntax" error.

    Correct Option: A

    The while() loop must have a conditional expression or it shows "Expression syntax" error.

    Report

-- advertisement --


  1. Which of then following is the correct output for the program given below?
    #include <stdio.h>
    int main()
    {
    int k = 5;
    while ( k++ != 5)
    printf ("%d", ++k);
    printf ("\n");
    return 0;
    }
    1. 5 6 7 ........ 127 0 1 2 3 4
    2. 5 6 7.........65535 0 1 2 3 4
    3. 5 6 ...........32767 -32766 -32765 ...... 3 4
    4. No output
  1. View Hint | View Answer | Workspace | Discuss In Forum | Report

    Condition in while loop is false.

    Correct Option: D

    Condition in while loop is false.

    Report

  1. Which of the following statement are correct about the program given below?
    #include <stdio.h>
    int main ( )
    {
    char ch;
    while (ch = 0; ch <= 255; ch++)
    printf ("ASCII value %d Character %c\n", ch, ch);
    return 0;
    }
    1. The program goes in an infinite loop.
    2. The program prints all the ASCII values with its corresponding characters.
    3. Error: ch should be declared as an int.
    4. The program reports an error as while loop cannot take the form of a for loop.
  1. View Hint | View Answer | Workspace | Discuss In Forum | Report

    The program reports an error as while loop cannot take the form of a for loop.

    Correct Option: D

    The program reports an error as while loop cannot take the form of a for loop.

    Report

-- advertisement --

-- advertisement --