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>
    int main()
    {
        float fval=7.29;
        printf("%d\n", (int)fval);
        return 0;
    }
    


  • Options
  • A. 0
  • B. 0.0
  • C. 7.0
  • D. 7

  • Correct Answer


  • Explanation
    printf("%d\n", (int)fval); It prints '7'. because, we typecast the (int)fval in to integer. It converts the float value to the nearest integer value.

    More questions

    • 1. Will the program compile successfully?
      #include<stdio.h>
      #define X (4+Y)
      #define Y (X+3)
      
      int main()
      {
          printf("%d\n", 4*X+2);
          return 0;
      }
      

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 2. Will the program compile successfully?
      #include<stdio.h>
      
      int main()
      {
          printf("India" "CURIOUSTAB\n");
          return 0;
      }
      

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 3. Once preprocessing is over and the program is sent for the compilation the macros are removed from the expanded source code.

    • Options
    • A. True
    • B. False
    • Discuss
    • 4. A header file contains macros, structure declaration and function prototypes.

    • Options
    • A. True
    • B. False
    • Discuss
    • 5. Point out the error in the program?
      #include<stdio.h>
      
      int main()
      {
          struct emp
          {
              char name[25];
              int age;
              float bs;
          };
          struct emp e;
          e.name = "Suresh";
          e.age = 25;
          printf("%s %d\n", e.name, e.age);
          return 0;
      }
      

    • Options
    • A. Error: Lvalue required/incompatible types in assignment
    • B. Error: invalid constant expression
    • C. Error: Rvalue required
    • D. No error, Output: Suresh 25
    • Discuss
    • 6. What will be the output of the program in 16 bit platform (Turbo C under DOS)?
      #include<stdio.h>
      
      int main()
      {
          struct value
          {
              int bit1:1;
              int bit3:4;
              int bit4:4;
          }bit;
          printf("%d\n", sizeof(bit));
          return 0;
      }
      

    • Options
    • A. 1
    • B. 2
    • C. 4
    • D. 9
    • Discuss
    • 7. What will be the output of the program If the integer is 4bytes long?
      #include<stdio.h>
      
      int main()
      {
          int ***r, **q, *p, i=8;
          p = &i;
          q = &p;
          r = &q;
          printf("%d, %d, %d\n", *p, **q, ***r);
          return 0;
      }
      

    • Options
    • A. 8, 8, 8
    • B. 4000, 4002, 4004
    • C. 4000, 4004, 4008
    • D. 4000, 4008, 4016
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char *str;
          str = "%d\n";
          str++;
          str++;
          printf(str-2, 300);
          return 0;
      }
      

    • Options
    • A. No output
    • B. 30
    • C. 3
    • D. 300
    • Discuss
    • 9. What will be the output of the program?
      #include<stdio.h>
      #define SQUARE(x) x*x
      
      int main()
      {
          float s=10, u=30, t=2, a;
          a = 2*(s-u*t)/SQUARE(t);
          printf("Result = %f", a);
          return 0;
      }
      

    • Options
    • A. Result = -100.000000
    • B. Result = -25.000000
    • C. Result = 0.000000
    • D. Result = 100.000000
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int i=4, j=-1, k=0, w, x, y, z;
          w = i || j || k;
          x = i && j && k;
          y = i || j &&k;
          z = i && j || k;
          printf("%d, %d, %d, %d\n", w, x, y, z);
          return 0;
      }
      

    • Options
    • A. 1, 1, 1, 1
    • B. 1, 1, 0, 1
    • C. 1, 0, 0, 1
    • D. 1, 0, 1, 1
    • Discuss


    Comments

    There are no comments.

Enter a new Comment