logo

CuriousTab

CuriousTab

Discussion


Home C Programming Command Line Arguments Comments

  • Question
  • What will be the output of the program if it is executed like below?
    cmd> sample
    /* sample.c */
    #include<stdio.h>
    
    int main(int argc, char **argv)
    {
        printf("%s\n", argv[argc-1]);
        return 0;
    }
    


  • Options
  • A. 0
  • B. sample
  • C. samp
  • D. No output

  • Correct Answer
  • sample 


  • Command Line Arguments problems


    Search Results


    • 1. A pointer union CANNOT be created

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 2. Will the following code work?
      #include<stdio.h>
      #include<malloc.h>
      
      struct emp
      {
          int len;
          char name[1];
      };
      int main()
      {
          char newname[] = "Rahul";
          struct emp *p = (struct emp *) malloc(sizeof(struct emp) -1 +
                          strlen(newname)+1);
      
          p->len = strlen(newname);
          strcpy(p -> name, newname);
          printf("%d %s\n", p->len, p->name);
          return 0;
      }
      

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 3. Will the following declaration work?
      typedef struct s
      {
          int a;
          float b;
      }s;
      

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 4. By default structure variable will be of auto storage class

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 5. Is it necessary that the size of all elements in a union should be same?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 6. 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
    • 7. 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
    • 8. 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
    • 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 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


    Comments

    There are no comments.

Enter a new Comment