logo

CuriousTab

CuriousTab

Discussion


Home C Programming Floating Point Issues See What Others Are Saying!
  • Question
  • What will be the output of the program?
    #include<stdio.h>
    #include<math.h>
    int main()
    {
        printf("%d, %d, %d\n", sizeof(3.14f), sizeof(3.14), sizeof(3.14l));
        return 0;
    }
    


  • Options
  • A. 4, 4, 4
  • B. 4, 8, 8
  • C. 4, 8, 10
  • D. 4, 8, 12

  • Correct Answer
  • 4, 8, 10 

    Explanation
    sizeof(3.14f) here '3.14f' specifies the float data type. Hence size of float is 4 bytes.

    sizeof(3.14) here '3.14' specifies the double data type. Hence size of float is 8 bytes.

    sizeof(3.14l) here '3.14l' specifies the long double data type. Hence size of float is 10 bytes.

    Note: If you run the above program in Linux platform (GCC Compiler) it will give 4, 8, 12 as output. If you run in Windows platform (TurboC Compiler) it will give 4, 8, 10 as output. Because, C is a machine dependent language.


    More questions

    • 1. A function that receives variable number of arguments should use va_arg() to extract the last argument from the variable argument list.

    • Options
    • A. True
    • B. False
    • Discuss
    • 2. Bitwise & can be used to check if more than one bit in a number is on.

    • Options
    • A. True
    • B. False
    • Discuss
    • 3. The preprocessor can trap simple errors like missing declarations, nested comments or mismatch of braces.

    • Options
    • A. True
    • B. False
    • Discuss
    • 4. It is necessary that a header files should have a .h extension?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 5. Bitwise | can be used to set multiple bits in number.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 6. Bitwise & can be used to check if a bit in number is set or not.

    • Options
    • A. True
    • B. False
    • Discuss
    • 7. A pointer union CANNOT be created

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      #include<stdlib.h>
      
      int main()
      {
          union test
          {
              int i;
              float f;
              char c;
          };
          union test *t;
          t = (union test *)malloc(sizeof(union test));
          t->f = 10.10f;
          printf("%f", t->f);
          return 0;
      }
      

    • Options
    • A. 10
    • B. Garbage value
    • C. 10.100000
    • D. Error
    • Discuss
    • 9. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int x=4, y, z;
          y = --x;
          z = x--;
          printf("%d, %d, %d\n", x, y, z);
          return 0;
      }
      

    • Options
    • A. 4, 3, 3
    • B. 4, 3, 2
    • C. 3, 3, 2
    • D. 2, 3, 3
    • Discuss
    • 10. Functions cannot return a floating point number

    • Options
    • A. Yes
    • B. No
    • Discuss


    Comments

    There are no comments.

Enter a new Comment