logo

CuriousTab

CuriousTab

Discussion


Home C Programming Control Instructions See What Others Are Saying!
  • Question
  • What will be the output of the program?
    #include<stdio.h>
    int main()
    {
        int x = 10, y = 20;
        if(!(!x) && x)
            printf("x = %d\n", x);
        else
            printf("y = %d\n", y);
        return 0;
    }
    


  • Options
  • A. y =20
  • B. x = 0
  • C. x = 10
  • D. x = 1

  • Correct Answer
  • x = 10 

    Explanation
    The logical not operator takes expression and evaluates to true if the expression is false and evaluates to false if the expression is true. In other words it reverses the value of the expression.

    Step 1: if(!(!x) && x)
    Step 2: if(!(!10) && 10)
    Step 3: if(!(0) && 10)
    Step 3: if(1 && 10)
    Step 4: if(TRUE) here the if condition is satisfied. Hence it prints x = 10.


    More questions

    • 1. What is the output of the program given below?
      #include<stdio.h>
      int main()
      {
          enum status { pass, fail, atkt};
          enum status stud1, stud2, stud3;
          stud1 = pass;
          stud2 = atkt;
          stud3 = fail;
          printf("%d, %d, %d\n", stud1, stud2, stud3);
          return 0;
      }
      

    • Options
    • A. 0, 1, 2
    • B. 1, 2, 3
    • C. 0, 2, 1
    • D. 1, 3, 2
    • Discuss
    • 2. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          char ch;
          ch = 'A';
          printf("The letter is");
          printf("%c", ch >= 'A' && ch <= 'Z'? ch + 'a' - 'A':ch);
          printf("Now the letter is");
          printf("%c\n", ch >= 'A' && ch <= 'Z'? ch : ch + 'a' - 'A');
          return 0;
      }
      

    • Options
    • A. The letter is a
      Now the letter is A
    • B. The letter is A
      Now the letter is a
    • C. Error
    • D. None of above
    • Discuss
    • 3. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int k, num=30;
          k = (num>5? (num <=10? 100 : 200): 500);
          printf("%d\n", num);
          return 0;
      }
      

    • Options
    • A. 200
    • B. 30
    • C. 100
    • D. 500
    • Discuss
    • 4. If a function contains two return statements successively, the compiler will generate warnings. Yes/No?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 5. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char *str;
          str = "%s";
          printf(str, "K\n");
          return 0;
      }
      

    • Options
    • A. Error
    • B. No output
    • C. K
    • D. %s
    • Discuss
    • 6. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char str1[] = "India";
          char str2[] = "CURIOUSTAB";
          char *s1 = str1, *s2=str2;
          while(*s1++ = *s2++)
              printf("%s", str1);
      
          printf("\n");
          return 0;
      }
      

    • Options
    • A. CuriousTab
    • B. BndiaBIdiaCURIOUSTABia
    • C. India
    • D. (null)
    • Discuss
    • 7. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int x=30, *y, *z;
          y=&x; /* Assume address of x is 500 and integer is 4 byte size */
          z=y;
          *y++=*z++;
          x++;
          printf("x=%d, y=%d, z=%d\n", x, y, z);
          return 0;
      }
      

    • Options
    • A. x=31, y=502, z=502
    • B. x=31, y=500, z=500
    • C. x=31, y=498, z=498
    • D. x=31, y=504, z=504
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char *p;
          p="hello";
          printf("%s\n", *&*&p);
          return 0;
      }
      

    • Options
    • A. llo
    • B. hello
    • C. ello
    • D. h
    • Discuss
    • 9. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int i=3, *j, k;
          j = &i;
          printf("%d\n", i**j*i+*j);
          return 0;
      }
      

    • Options
    • A. 30
    • B. 27
    • C. 9
    • D. 3
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          printf("%c\n", 7["CuriousTab"]);
          return 0;
      }
      

    • Options
    • A. Error: in printf
    • B. Nothing will print
    • C. print "X" of CuriousTab
    • D. print "7"
    • Discuss


    Comments

    There are no comments.

Enter a new Comment