Home / C Programming / Control Instructions :: Discussion

Discussion :: Control Instructions

  1. Point out the error, if any in the while loop.

    #include
     int main()
     {   
         void fun();   
         int i = 1;     
         while(i 5)    
         {       
            printf("%d\n", i);         
            if(2)       
                goto here;   
      } 
      return 0;
      } 
      void fun() 
      {
         here:   
         printf("It works");
      } 
    

  2. A.

    No Error: prints "It works"

    B.

    Error: fun() cannot be accessed

    C.

    Error: goto cannot takeover control to other function

    D.

    No error

    View Answer

    Workspace

    Answer : Option C

    Explanation :

    A label is used as the target of a goto statement, and that label must be within the same function as the goto statement.

    Syntax: goto ;
    Control is unconditionally transferred to the location of a local label specified by .
    Example:

     

     #include  int main() {     int i=1;     while(i>0)     {         printf("%d", i++);         if(i==5)           goto mylabel;     }     mylabel:     return 0; }  

     

    Output: 1,2,3,4


Be The First To Comment