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 MIN(x, y) (x<y)? x : y;
    int main()
    {
        int x=3, y=4, z;
        z = MIN(x+y/2, y-1);
        if(z > 0)
            printf("%d\n", z);
        return 0;
    }
    


  • Options
  • A. 3
  • B. 4
  • C. 0
  • D. No output

  • Correct Answer


  • Explanation
    The macro MIN(x, y) (x<y)? x : y; returns the smallest value from the given two numbers.

    Step 1: int x=3, y=4, z; The variable x, y, z are declared as an integer type and the variable x, y are initialized to value 3, 4 respectively.

    Step 2: z = MIN(x+y/2, y-1); becomes,

    => z = (x+y/2 < y-1)? x+y/2 : y - 1;

    => z = (3+4/2 < 4-1)? 3+4/2 : 4 - 1;

    => z = (3+2 < 4-1)? 3+2 : 4 - 1;

    => z = (5 < 3)? 5 : 3;

    The macro return the number 3 and it is stored in the variable z.

    Step 3: if(z > 0) becomes if(3 > 0) here the if condition is satisfied. It executes the if block statements.

    Step 4: printf("%d\n", z);. It prints the value of variable z.

    Hence the output of the program is 3


    More questions

    • 1. What will be the output of the program in 16-bit platform (under DOS)?
      #include<stdio.h>
      
      int main()
      {
          struct node
          {
              int data;
              struct node *link;
          };
          struct node *p, *q;
          p = (struct node *) malloc(sizeof(struct node));
          q = (struct node *) malloc(sizeof(struct node));
          printf("%d, %d\n", sizeof(p), sizeof(q));
          return 0;
      }
      

    • Options
    • A. 2, 2
    • B. 8, 8
    • C. 5, 5
    • D. 4, 4
    • Discuss
    • 2. Is it true that too many recursive calls may result into stack overflow?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 3. The operator used to get value at address stored in a pointer variable is

    • Options
    • A. *
    • B. &
    • C. &&
    • D. ||
    • Discuss
    • 4. If the size of integer is 4bytes, What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int arr[] = {12, 13, 14, 15, 16};
          printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
          return 0;
      }
      

    • Options
    • A. 10, 2, 4
    • B. 20, 4, 4
    • C. 16, 2, 2
    • D. 20, 2, 2
    • Discuss
    • 5. What do the following declaration signify?
      void *cmp();

    • Options
    • A. cmp is a pointer to an void type.
    • B. cmp is a void type pointer variable.
    • C. cmp is a function that return a void pointer.
    • D. cmp function returns nothing.
    • Discuss
    • 6. A function may have any number of return statements each returning different values.

    • Options
    • A. True
    • B. False
    • Discuss
    • 7. In C all functions except main() can be called recursively.

    • Options
    • A. True
    • B. False
    • Discuss
    • 8. Input/output function prototypes and macros are defined in which header file?

    • Options
    • A. conio.h
    • B. stdlib.h
    • C. stdio.h
    • D. dos.h
    • Discuss
    • 9. For a function receives variable number of arguments it is necessary that the function should receive at least one fixed argument.

    • Options
    • A. True
    • B. False
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      int X=40;
      int main()
      {
          int X=20;
          printf("%d\n", X);
          return 0;
      }
      

    • Options
    • A. 20
    • B. 40
    • C. Error
    • D. No Output
    • Discuss


    Comments

    There are no comments.

Enter a new Comment