int main(int argc, char *arg"> int main(int argc, char *arg">
logo

CuriousTab

CuriousTab

Discussion


Home C Programming Command Line Arguments Comments

  • Question
  • 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<stdio.h>
    
    int main(int argc, char *argv[])
    {
        printf("%s", argv[0]);
        return 0;
    }
    


  • Options
  • A. SAMPLE.C
  • B. C:\TC\MYPROC.EXE
  • C. C:\TC
  • D. Error

  • Correct Answer
  • C:\TC\MYPROC.EXE 

    Explanation
    In order to execute it from DOS shell, we have to run the created EXE file by entering the exe file name as C:\TC>myproc <enter>.

  • Command Line Arguments problems


    Search Results


    • 1. 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
    • 2. 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
    • 3. What will be the output of the program (sample.c) given below if it is executed from the command line?
      cmd> sample "*.c"
      /* sample.c */
      #include<stdio.h>
      
      int main(int argc, int *argv)
      {
          int i;
          for(i=1; i<argc; i++)
              printf("%s\n", argv[i]);
          return 0;
      }
      

    • Options
    • A. *.c
    • B. "*.c"
    • C. sample *.c
    • D. List of all files and folders in the current directory
    • Discuss
    • 4. 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 sizeofargv, char *argv[])
      {
          while(sizeofargv)
              printf("%s", argv[--sizeofargv]);
          return 0;
      }
      

    • Options
    • A. sample friday tuesday sunday
    • B. sample friday tuesday
    • C. sunday tuesday friday sample
    • D. sunday tuesday friday
    • Discuss
    • 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<stdio.h>
      #include<stdlib.h>
      
      int main(int argc, char **argv)
      {
          printf("%s\n", *++argv);
          return 0;
      }
      

    • Options
    • A. myprog
    • B. one
    • C. two
    • D. three
    • Discuss
    • 6. What will be the output of the program in Turbo C?
      #include<stdio.h>
      
      int main(int argc, char *argv, char *env[])
      {
          int i;
          for(i=1; i<argc; i++)
              printf("%s\n", env[i]);
          return 0;
      }
      

    • Options
    • A. List of all environment variables
    • B. List of all command-line arguments
    • C. count of command-line arguments
    • D. Error: cannot have more than two arguments in main()
    • Discuss
    • 7. 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<stdio.h>
      
      int main(int argc, char *argv[])
      {
          int i;
          for(i=1; i<argc; i++)
              printf("%c", argv[i][0]);
          return 0;
      }
      

    • Options
    • A. oot
    • B. ott
    • C. nwh
    • D. eoe
    • Discuss
    • 8. 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<stdio.h>
      #include<stdlib.h>
      
      int main(int argc, char **argv)
      {
          int i, j=0;
          for(i=0; i<argc; i++)
              j = j+atoi(argv[i]);
          printf("%d\n", j);
          return 0;
      }
      

    • Options
    • A. 123
    • B. 6
    • C. Error
    • D. "123"
    • Discuss
    • 9. What will be the output of the program
      #include<stdio.h>
      void fun(int);
      
      int main(int argc)
      {
          printf("%d ", argc);
          fun(argc);
          return 0;
      }
      void fun(int i)
      {
          if(i!=4)
              main(++i);
      }
      

    • Options
    • A. 1 2 3
    • B. 1 2 3 4
    • C. 2 3 4
    • D. 1
    • Discuss
    • 10. What will be the output of the program (myprog.c) given below if it is executed from the command line?
      cmd> myprog friday tuesday sunday
      /* myprog.c */
      #include<stdio.h>
      
      int main(int argc, char *argv[])
      {
          printf("%c", *++argv[1]);
          return 0;
      }
      

    • Options
    • A. r
    • B. f
    • C. m
    • D. y
    • Discuss


    Comments

    There are no comments.

Enter a new Comment