logo

CuriousTab

CuriousTab

Discussion


Home C Programming Strings See What Others Are Saying!
  • Question
  • What will be the output of the program?
    #include<stdio.h>
    
    int main()
    {
        char p[] = "%d\n";
        p[1] = 'c';
        printf(p, 65);
        return 0;
    }
    


  • Options
  • A. A
  • B. a
  • C. c
  • D. 65

  • Correct Answer


  • Explanation
    Step 1: char p[] = "%d\n"; The variable p is declared as an array of characters and initialized with string "%d".

    Step 2: p[1] = 'c'; Here, we overwrite the second element of array p by 'c'. So array p becomes "%c".

    Step 3: printf(p, 65); becomes printf("%c", 65);

    Therefore it prints the ASCII value of 65. The output is 'A'.


    More questions

    • 1. It is necessary to call the macro va_end if va_start is called in the function.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 2. Left shifting a number by 1 is always equivalent to multiplying it by 2.

    • Options
    • A. True
    • B. False
    • Discuss
    • 3. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          printf("%%%%\n");
          return 0;
      }
      

    • Options
    • A. %%%%%
    • B. %%
    • C. No output
    • D. Error
    • Discuss
    • 4. A function that receives variable number of arguments should use va_arg() to extract arguments from the variable argument list.

    • Options
    • A. True
    • B. False
    • Discuss
    • 5. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          float a = 0.7;
          if(0.7 > a)
              printf("Hi\n");
          else
              printf("Hello\n");
          return 0;
      }
      

    • Options
    • A. Hi
    • B. Hello
    • C. Hi Hello
    • D. None of above
    • Discuss
    • 6. 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
    • 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 argc, char *argv[])
      {
          printf("%c", *++argv[2] );
          return 0;
      }
      

    • Options
    • A. s
    • B. f
    • C. u
    • D. r
    • Discuss
    • 8. Point out the error in the program.
      #include<stdio.h>
      
      int main()
      {
          const int k=7;
          int *const q=&k;
          printf("%d", *q);
          return 0;
      }
      

    • Options
    • A. Error: RValue required
    • B. Error: Lvalue required
    • C. Error: cannot convert from 'const int *' to 'int *const'
    • D. No error
    • Discuss
    • 9. Bit fields CANNOT be used in union.

    • Options
    • A. True
    • B. False
    • Discuss
    • 10. What will be the output of the program (myprog.c) given below if it is executed from the command line?
      cmd> myprog 10 20 30
      /* myprog.c */
      #include<stdio.h>
      
      int main(int argc, char **argv)
      {
          int i;
          for(i=0; i<argc; i++)
              printf("%s\n", argv[i]);
          return 0;
      }
      

    • Options
    • A. 10 20 30
    • B. myprog 10 20
    • C. myprog 10 20 30
    • D. 10 20
    • Discuss


    Comments

    There are no comments.

Enter a new Comment