logo

CuriousTab

CuriousTab

Discussion


Home C Programming Strings See What Others Are Saying!
  • Question
  • If char=1, int=4, and float=4 bytes size, What will be the output of the program?
    #include<stdio.h>
    
    int main()
    {
        char ch = 'A';
        printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));
        return 0;
    }
    


  • Options
  • A. 1, 2, 4
  • B. 1, 4, 4
  • C. 2, 2, 4
  • D. 2, 4, 8

  • Correct Answer
  • 1, 4, 4 

    Explanation
    Step 1: char ch = 'A'; The variable ch is declared as an character type and initialized with value 'A'.

    Step 2:

    printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14));

    The sizeof function returns the size of the given expression.

    sizeof(ch) becomes sizeof(char). The size of char is 1 byte.

    sizeof('A') becomes sizeof(65). The size of int is 4 bytes (as mentioned in the question).

    sizeof(3.14f). The size of float is 4 bytes.

    Hence the output of the program is 1, 4, 4


    More questions

    • 1. The '->' operator can be used to access structures elements using a pointer to a structure variable only

    • Options
    • A. True
    • B. False
    • Discuss
    • 2. What are the types of linkages?

    • Options
    • A. Internal and External
    • B. External, Internal and None
    • C. External and None
    • D. Internal
    • Discuss
    • 3. Out of fgets() and gets() which function is safe to use?

    • Options
    • A. gets()
    • B. fgets()
    • Discuss
    • 4. A structure can be nested inside another structure.

    • Options
    • A. True
    • B. False
    • Discuss
    • 5. 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
    • 6. Which of the following statement is True?

    • Options
    • A. User has to explicitly define the numeric value of enumerations
    • B. User has a control over the size of enumeration variables.
    • C. Enumeration can have an effect local to the block, if desired
    • D. Enumerations have a global effect throughout the file.
    • Discuss
    • 7. Point out the error in the program?
      struct emp
      {
          int ecode;
          struct emp *e;
      };
      

    • Options
    • A. Error: in structure declaration
    • B. Linker Error
    • C. No Error
    • D. None of above
    • Discuss
    • 8. Point out the error in the program?
      #include<stdio.h>
      
      int main()
      {
          union a
          {
              int i;
              char ch[2];
          };
          union a z1 = {512};
          union a z2 = {0, 2};
          return 0;
      }
      

    • Options
    • A. Error: invalid union declaration
    • B. Error: in Initializing z2
    • C. No error
    • D. None of above
    • Discuss
    • 9. Point out the error in the program?
      struct emp
      {
          int ecode;
          struct emp e;
      };
      

    • Options
    • A. Error: in structure declaration
    • B. Linker Error
    • C. No Error
    • D. None of above
    • Discuss
    • 10. 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


    Comments

    There are no comments.

Enter a new Comment