logo

CuriousTab

CuriousTab

Discussion


Home C Programming Expressions See What Others Are Saying!
  • Question
  • 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

  • Correct Answer
  • 1, 0, 1, 1 

    Explanation
    Step 1: int i=4, j=-1, k=0, w, x, y, z; here variable i, j, k, w, x, y, z are declared as an integer type and the variable i, j, k are initialized to 4, -1, 0 respectively.

    Step 2: w = i || j || k; becomes w = 4 || -1 || 0;. Hence it returns TRUE. So, w=1

    Step 3: x = i && j && k; becomes x = 4 && -1 && 0; Hence it returns FALSE. So, x=0

    Step 4: y = i || j &&k; becomes y = 4 || -1 && 0; Hence it returns TRUE. So, y=1

    Step 5: z = i && j || k; becomes z = 4 && -1 || 0; Hence it returns TRUE. So, z=1.

    Step 6: printf("%d, %d, %d, %d\n", w, x, y, z); Hence the output is "1, 0, 1, 1".


    More questions

    • 1. What will be the output of the program (in Turbo C under DOS)?
      #include<stdio.h>
      
      int main()
      {
          char huge *near *far *ptr1;
          char near *far *huge *ptr2;
          char far *huge *near *ptr3;
          printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
          return 0;
      }
      

    • Options
    • A. 4, 4, 8
    • B. 2, 4, 4
    • C. 4, 4, 2
    • D. 2, 4, 8
    • Discuss
    • 2. 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
    • 3. Is it true that too many recursive calls may result into stack overflow?

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

    • Options
    • A. *
    • B. &
    • C. &&
    • D. ||
    • Discuss
    • 5. 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
    • 6. 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
    • 7. A function may have any number of return statements each returning different values.

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

    • Options
    • A. True
    • B. False
    • Discuss
    • 9. 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
    • 10. 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


    Comments

    There are no comments.

Enter a new Comment