logo

CuriousTab

CuriousTab

Discussion


Home C Programming C Preprocessor See What Others Are Saying!
  • Question
  • What will be the output of the program?
    #include<stdio.h>
    #define MAX(a, b, c) (a>b? a>c? a : c: b>c? b : c)
    
    int main()
    {
        int x;
        x = MAX(3+2, 2+7, 3+7);
        printf("%d\n", x);
        return 0;
    }
    


  • Options
  • A. 5
  • B. 9
  • C. 10
  • D. 3+7

  • Correct Answer
  • 10 

    Explanation
    The macro MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c) returns the biggest of given three numbers.

    Step 1: int x; The variable x is declared as an integer type.

    Step 2: x = MAX(3+2, 2+7, 3+7); becomes,

    => x = (3+2 >2+7 ? 3+2 > 3+7 ? 3+2 : 3+7: 2+7 > 3+7 ? 2+7 : 3+7)

    => x = (5 >9 ? (5 > 10 ? 5 : 10): (9 > 10 ? 9 : 10) )

    => x = (5 >9 ? (10): (10) )

    => x = 10

    Step 3: printf("%d\n", x); It prints the value of 'x'.

    Hence the output of the program is "10".


    More questions

    • 1. Is it necessary that in a function which accepts variable argument list there should be at least be one fixed argument?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 2. Bitwise can be used to generate a random number.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 3. 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
    • 4. Bitwise & can be used to check if more than one bit in a number is on.

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

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

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

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

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

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 10. 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


    Comments

    There are no comments.

Enter a new Comment