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()
    {
        int i;
        char a[] = "\0";
        if(printf("%s", a))
            printf("The string is not empty\n");
        else
            printf("The string is empty\n");
        return 0;
    }
    


  • Options
  • A. The string is not empty
  • B. The string is empty
  • C. No output
  • D. 0

  • Correct Answer
  • The string is empty 

    Explanation
    The function printf() returns the number of charecters printed on the console.

    Step 1: char a[] = '\0'; The variable a is declared as an array of characters and it initialized with "\0". It denotes that the string is empty.

    Step 2: if(printf("%s", a)) The printf() statement does not print anything, so it returns '0'(zero). Hence the if condition is failed.

    In the else part it prints "The string is empty".


    More questions

    • 1. If return type for a function is not specified, it defaults to int

    • Options
    • A. True
    • B. False
    • Discuss
    • 2. A function cannot be defined inside another function

    • Options
    • A. True
    • B. False
    • Discuss
    • 3. Usually recursion works slower than loops.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 4. In the following program add a statement in the function fact() such that the factorial gets stored in j.
      #include<stdio.h>
      void fact(int*);
      
      int main()
      {
          int i=5;
          fact(&i);
          printf("%d\n", i);
          return 0;
      }
      void fact(int *j)
      {
          static int s=1;
          if(*j!=0)
          {
              s = s**j;
              *j = *j-1;
              fact(j);
              /* Add a statement here */
          }
      }
      

    • Options
    • A. j=s;
    • B. *j=s;
    • C. *j=&s;
    • D. &j=s;
    • Discuss
    • 5. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          unsigned char i = 0x80;
          printf("%d\n", i<<1);
          return 0;
      }
      

    • Options
    • A. 0
    • B. 256
    • C. 100
    • D. 80
    • Discuss
    • 6. What will be the output of the program in 16 bit platform (Turbo C under DOS)?
      #include<stdio.h>
      
      int main()
      {
          int fun();
          int i;
          i = fun();
          printf("%d\n", i);
          return 0;
      }
      int fun()
      {
          _AX = 1990;
      }
      

    • Options
    • A. Garbage value
    • B. 0 (Zero)
    • C. 1990
    • D. No output
    • Discuss
    • 7. Range of double is -1.7e-38 to 1.7e+38 (in 16 bit platform - Turbo C under DOS)

    • Options
    • A. True
    • B. False
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char huge *near *far *ptr1;
          char near *far *huge *ptr2;
          char far *huge *near *ptr3;
          printf("%d, %d, %d\n", sizeof(**ptr1), sizeof(ptr2), sizeof(*ptr3));
          return 0;
      }
      

    • Options
    • A. 4, 4, 4
    • B. 2, 2, 2
    • C. 2, 8, 4
    • D. 2, 4, 8
    • Discuss
    • 9. The '.' operator can be used access structure elements using a structure variable.

    • Options
    • A. True
    • B. False
    • Discuss
    • 10. What will be the output of the program (sample.c) given below if it is executed from the command line (turbo c under DOS)?
      cmd> sample Good Morning
      /* sample.c */
      #include<stdio.h>
      
      int main(int argc, char *argv[])
      {
          printf("%d %s", argc, argv[1]);
          return 0;
      }
      

    • Options
    • A. 3 Good
    • B. 2 Good
    • C. Good Morning
    • D. 3 Morning
    • Discuss


    Comments

    There are no comments.

Enter a new Comment