logo

CuriousTab

CuriousTab

Discussion


Home C Programming Complicated Declarations See What Others Are Saying!
  • Question
  • What will be the output of the program?
    #include<stdio.h>
    typedef unsigned long int uli;
    typedef uli u;
    
    int main()
    {
        uli a;
        u b = -1;
        a = -1;
        printf("%lu, %lu", a, b);
        return 0;
    }
    


  • Options
  • A. 4343445454, 4343445454
  • B. 4545455434, 4545455434
  • C. 4294967295, 4294967295
  • D. Garbage values

  • Correct Answer
  • 4294967295, 4294967295 

    Explanation
    The system will treat the negative numbers with 2's complement method.

    For 'long int' system will occupy 4 bytes (32 bits).

    Therefore,

    Binary 1 : 00000000 00000000 00000000 00000001

    To represent -1, system uses the 2's complement value of 1. Add 1 to the 1's complement result to obtain 2's complement of 1.

    So, First take 1's complement of binary 1 (change all 0s to 1s and all 1s to 0s)

    1's complement of Binary 1:

    11111111 11111111 11111111 11111110

    2's complement of Binary 1: (Add 1 with the above result)

    11111111 11111111 11111111 11111111


    In HexaDecimal

    11111111 11111111 11111111 11111111 = FFFF FFFF FFFF FFFF

    In Unsigned Integer

    11111111 11111111 11111111 11111111 = 4294967295.


    More questions

    • 1. What will be the output of the program?
      #include<stdio.h>
      int check(int);
      int main()
      {
          int i=45, c;
          c = check(i);
          printf("%d\n", c);
          return 0;
      }
      int check(int ch)
      {
          if(ch >= 45)
              return 100;
          else
              return 10;
      }
      

    • Options
    • A. 100
    • B. 10
    • C. 1
    • D. 0
    • Discuss
    • 2. Point out the error, if any in the for loop.
      #include<stdio.h>
      int main()
      {
          int i=1;
          for(;;)
          {
              printf("%d\n", i++);
              if(i>10)
                 break;
          }
          return 0;
      }
      

    • Options
    • A. There should be a condition in the for loop
    • B. The two semicolons should be dropped
    • C. The for loop should be replaced with while loop.
    • D. No error
    • Discuss
    • 3. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          float a=0.7;
          if(a < 0.7)
              printf("C\n");
          else
              printf("C++\n");
          return 0;
      }
      

    • Options
    • A. C
    • B. C++
    • C. Compiler error
    • D. Non of above
    • Discuss
    • 4. Assuming, integer is 2 byte, What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          printf("%x\n", -2<<2);
          return 0;
      }
      

    • Options
    • A. ffff
    • B. 0  
    • C. fff8
    • D. Error
    • Discuss
    • 5. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int i;
          i = printf("How r u\n");
          i = printf("%d\n", i);
          printf("%d\n", i);
          return 0;
      }
      

    • Options
    • A. How r u
      7
      2
    • B. How r u
      8
      2
    • C. How r u
      1
      1
    • D. Error: cannot assign printf to variable
    • Discuss
    • 6. Will the program compile successfully?
      #include<stdio.h>
      
      int main()
      {
          #ifdef NOTE
              int a;
              a=10;
          #else
              int a;
              a=20;
          #endif
          printf("%d\n", a);
          return 0;
      }
      

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 7. There exists a way to prevent the same file from getting #included twice in the same program.

    • Options
    • A. True
    • B. False
    • Discuss
    • 8. Will the following program print the message infinite number of times?
      #include<stdio.h>
      #define INFINITELOOP while(1)
      
      int main()
      {
          INFINITELOOP
          printf("CuriousTab");
          return 0;
      }
      

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 9. Declare the following statement?
      "A pointer to a function which receives nothing and returns nothing".

    • Options
    • A.
      void *(ptr)*int;
    • B.
      void *(*ptr)()
    • C.
      void *(*ptr)(*)
    • D.
      void (*ptr)()
    • Discuss
    • 10. 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
    • Discuss


    Comments

    There are no comments.

Enter a new Comment