10) break; } return "> 10) break; } return ">
logo

CuriousTab

CuriousTab

Discussion


Home C Programming Control Instructions See What Others Are Saying!
  • Question
  • Point out the error, if any in the while loop.
    #include<stdio.h>
    int main()
    {
        int i=1;
        while()
        {
            printf("%d\n", i++);
            if(i>10)
               break;
        }
        return 0;
    }
    


  • Options
  • A. There should be a condition in the while loop
  • B. There should be at least a semicolon in the while
  • C. The while loop should be replaced with for loop.
  • D. No error

  • Correct Answer
  • There should be a condition in the while loop 

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

    Example: while(i > 10){ ... }


    More questions

    • 1. What are the types of linkages?

    • Options
    • A. Internal and External
    • B. External, Internal and None
    • C. External and None
    • D. Internal
    • Discuss
    • 2. Out of fgets() and gets() which function is safe to use?

    • Options
    • A. gets()
    • B. fgets()
    • Discuss
    • 3. A structure can be nested inside another structure.

    • Options
    • A. True
    • B. False
    • Discuss
    • 4. What will be the output of the program (sample.c) given below if it is executed from the command line?
      cmd> sample one two three
      /* sample.c */
      #include<stdio.h>
      
      int main(int argc, char *argv[])
      {
          int i=0;
          i+=strlen(argv[1]);
          while(i>0)
          {
              printf("%c", argv[1][--i]);
          }
          return 0;
      }
      

    • Options
    • A. three two one
    • B. owt
    • C. eno
    • D. eerht
    • Discuss
    • 5. Which of the following statement is True?

    • Options
    • A. User has to explicitly define the numeric value of enumerations
    • B. User has a control over the size of enumeration variables.
    • C. Enumeration can have an effect local to the block, if desired
    • D. Enumerations have a global effect throughout the file.
    • Discuss
    • 6. Point out the error in the program?
      struct emp
      {
          int ecode;
          struct emp *e;
      };
      

    • Options
    • A. Error: in structure declaration
    • B. Linker Error
    • C. No Error
    • D. None of above
    • Discuss
    • 7. Point out the error in the program?
      #include<stdio.h>
      
      int main()
      {
          union a
          {
              int i;
              char ch[2];
          };
          union a z1 = {512};
          union a z2 = {0, 2};
          return 0;
      }
      

    • Options
    • A. Error: invalid union declaration
    • B. Error: in Initializing z2
    • C. No error
    • D. None of above
    • Discuss
    • 8. Point out the error in the program?
      struct emp
      {
          int ecode;
          struct emp e;
      };
      

    • Options
    • A. Error: in structure declaration
    • B. Linker Error
    • C. No Error
    • D. None of above
    • Discuss
    • 9. What will be the output of the program (sample.c) given below if it is executed from the command line?
      cmd> sample friday tuesday sunday
      /* sample.c */
      #include<stdio.h>
      
      int main(int argc, char *argv[])
      {
          printf("%c", **++argv);
          return 0;
      }
      

    • Options
    • A. s
    • B. f
    • C. sample
    • D. friday
    • Discuss
    • 10. What is the purpose of fflush() function.

    • Options
    • A. flushes all streams and specified streams.
    • B. flushes only specified stream.
    • C. flushes input/output buffer.
    • D. flushes file buffer.
    • Discuss


    Comments

    There are no comments.

Enter a new Comment