logo

CuriousTab

CuriousTab

Discussion


Home C Programming Strings Comments

  • Question
  • If the size of pointer is 4 bytes then What will be the output of the program?
    #include<stdio.h>
    
    int main()
    {
        char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"};
        printf("%d, %d", sizeof(str), strlen(str[0]));
        return 0;
    }
    


  • Options
  • A. 22, 4
  • B. 25, 5
  • C. 24, 5
  • D. 20, 2

  • Correct Answer
  • 24, 5 

    Explanation
    Step 1: char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"}; The variable str is declared as an pointer to the array of 6 strings.

    Step 2: printf("%d, %d", sizeof(str), strlen(str[0]));

    sizeof(str) denotes 6 * 4 bytes = 24 bytes. Hence it prints '24'

    strlen(str[0])); becomes strlen(Frogs)). Hence it prints '5';

    Hence the output of the program is 24, 5

    Hint: If you run the above code in 16 bit platform (Turbo C under DOS) the output will be 12, 5. Because the pointer occupies only 2 bytes. If you run the above code in Linux (32 bit platform), the output will be 24, 5 (because the size of pointer is 4 bytes).


    Strings problems


    Search Results


    • 1. What will be the output of the following program in 16 bit platform assuming that 1022 is memory address of the string "Hello1" (in Turbo C under DOS)?
      #include<stdio.h>
      
      int main()
      {
          printf("%u %s\n", &"Hello1", &"Hello2");
          return 0;
      }
      

    • Options
    • A. 1022 Hello2
    • B. Hello1 1022
    • C. Hello1 Hello2
    • D. 1022 1022
    • E. Error
    • Discuss
    • 2. 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
    • Discuss
    • 3. What will be the output of the program (Turbo C in 16 bit platform DOS)?
      #include<stdio.h>
      #include<string.h>
      
      int main()
      {
          char *str1 = "India";
          char *str2 = "CURIOUSTAB";
          char *str3;
          str3 = strcat(str1, str2);
          printf("%s %s\n", str3, str1);
          return 0;
      }
      

    • Options
    • A. CuriousTab India
    • B. CuriousTab CuriousTab
    • C. India India
    • D. Error
    • Discuss
    • 4. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char str[25] = "CuriousTab";
          printf("%s\n", &str+2);
          return 0;
      }
      

    • Options
    • A. Garbage value
    • B. Error
    • C. No output
    • D. diaCURIOUSTAB
    • Discuss
    • 5. What will be the output of the program?
      #include<stdio.h>
      #include<string.h>
      
      int main()
      {
          printf("%c\n", "abcdefgh"[4]);
          return 0;
      }
      

    • Options
    • A. Error
    • B. d
    • C. e
    • D. abcdefgh
    • Discuss
    • 6. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char str[] = "Nagpur";
          str[0]='K';
          printf("%s, ", str);
          str = "Kanpur";
          printf("%s", str+1);
          return 0;
      }
      

    • Options
    • A. Kagpur, Kanpur
    • B. Nagpur, Kanpur
    • C. Kagpur, anpur
    • D. Error
    • Discuss
    • 7. 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
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          printf(5+"Good Morning\n");
          return 0;
      }
      

    • Options
    • A. Good Morning
    • B. Good
    • C. M
    • D. Morning
    • Discuss
    • 9. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char str1[] = "Hello";
          char str2[10];
          char *t, *s;
          s = str1;
          t = str2;
          while(*t=*s)
              *t++ = *s++;
          printf("%s\n", str2);
          return 0;
      }
      

    • Options
    • A. Hello
    • B. HelloHello
    • C. No output
    • D. ello
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char str = "CuriousTab";
          printf("%s\n", str);
          return 0;
      }
      

    • Options
    • A. Error
    • B. CuriousTab
    • C. Base address of str
    • D. No output
    • Discuss


    Comments

    There are no comments.

Enter a new Comment