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. Bitwise | can be used to set a bit in number.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 2. Can we have an array of bit fields?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 3. By default structure variable will be of auto storage class

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 4. Bitwise can be used to reverse a sign of a number.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 5. 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
    • 6. Bitwise can be used to generate a random number.

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

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

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

    • Options
    • A. Yes
    • B. No
    • Discuss


    Comments

    There are no comments.

Enter a new Comment