Home / C Programming / Command Line Arguments :: Find Output of Program

C Programming :: Command Line Arguments

  1. What will be the output of the program (sample.c) given below if it is executed from the command line?
    cmd> sample monday tuesday wednesday thursday

     /* sample.c */
     #include 
    
     int main(int argc, char *argv[]) 
     {   
         while(--argc>0)         
             printf("%s", *++argv);     
         return 0;
     } 
    

  2. A.

    sample monday tuesday wednesday thursday

    B.

    monday tuesday wednesday thursday

    C.

    monday tuesday thursday

    D.

    tuesday

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. If the following program (myproc.c) is present in the directory "C:\TC" then what will be output of the program if run it from DOS shell?

     /* myproc.c */
     #include 
    
     int main(int argc, char *argv[]) 
     {  
          printf("%s", argv[0]);   
          return 0; 
     }
    

  4. A.

    SAMPLE.C

    B.

    C:\TC\MYPROC.EXE

    C.

    C:\TC

    D.

    Error

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. What will be the output of the program (myprog.c) given below if it is executed from the command line?
    cmd> myprog one two three

     /* myprog.c */
     #include 
    
     int main(int argc, char *argv[])
     {    
        int i;   
        for(i=1; i"%c", argv[i][0]);         
        return 0; 
     } 
    
    

  6. A.

    oot

    B.

    ott

    C.

    nwh

    D.

    eoe

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. What will be the output of the program (sample.c) given below if it is executed from the command line?
    cmd> sample 1 2 3
    cmd> sample 2 2 3
    cmd> sample 3 2 3

    /* sample.c */
     #include 
    
     int main(int argc, char *argv[])
     {    
         printf("%s\n", argv[0]);       
         return 0;
     } 
    

  8. A.

    sample 3 2 3

    B.

    sample 1 2 3

    C.

    sample

    D.

    Error

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. What will be the output of the program (myprog.c) given below if it is executed from the command line?
    cmd> myprog 1 2 3

    /* myprog.c */
     #include 
     #include
    
      int main(int argc, char **argv)
      {   
         int i, j=0;  
         for(i=0; i"%d\n", j); 
       return 0; 
    } 

     

  10. A.

    123

    B.

    6

    C.

    Error

    D.

    "123"

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. 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 
    
     int main(int sizeofargv, char *argv[]) 
     {  
       while(sizeofargv)          
           printf("%s", argv[--sizeofargv]); 
        return 0;
     } 
    

  12. A.

    sample friday tuesday sunday

    B.

    sample friday tuesday

    C.

    sunday tuesday friday sample

    D.

    sunday tuesday friday

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. 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  
    
    int main(int argc, char *argv[]) 
    {   
        printf("%c", *++argv[2] );       
        return 0; 
    } 
    

  14. A.

    s

    B.

    f

    C.

    u

    D.

    r

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. What will be the output of the program (myprog.c) given below if it is executed from the command line?
    cmd> myprog one two three

      /* myprog.c */
      #include 
      #include 
    
      int main(int argc, char **argv)
      {    
           int i;   
           for(i=1; i3; i++)    
              printf("%u\n", &argv[i]);   
            return 0;
       } 

    If the first value printed by the above program is 65517, what will be the rest of output?

  16. A.

    65525 65531

    B.

    65519 65521

    C.

    65517 65517

    D.

    65521 65525

    View Answer

    Workspace

    Discuss Discuss in Forum