InidBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming Java Programming
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Group Disucssion HR Interview Questions Technical Interview Questions Body Language

Exercise

"Act well your part; there all honor lies."
- Alexander Pope

C Programming - Bitwise Operators

@ : Home > C Programming > Bitwise Operators > Point Out Correct Statements
1. 

Which of the following statements are correct about the program?

#include<stdio.h>

int main()
{
    unsigned int num;
    int i;
    scanf("%u", &num);
    for(i=0; i<16; i++)
    {
        printf("%d", (num<<i & 1<<15)?1:0);
    }
    return 0;
}

A. It prints all even bits from num
B. It prints all odd bits from num
C.
It prints binary equivalent num
D. Error

2. 

Which of the following statements are correct about the program?

#include<stdio.h>

int main()
{
    unsigned int num;
    int c=0;
    scanf("%u", &num);
    for(;num;num>=1)
    {
        if(num & 1)
            c++;
    }
    printf("%d", c);
    return 0;
}

A.
It counts the number of bits that are on in the number num.
B. It sets all bits in the number num to 1
C. It sets all bits in the number num to 0
D. Error

3. 

Which of the following statements are correct about the program?

#include<stdio.h>
char *fun(unsigned int num, int base);

int main()
{
    char *s;
    s=fun(128, 2);
    s=fun(128, 16);
    printf("%s\n",s);
    return 0;
}
char *fun(unsigned int num, int base)
{
    static char buff[33];
    char *ptr = &buff[sizeof(buff)-1];
    *ptr = '\0';
    do
    {
        *--ptr = "0123456789abcdef"[num %base];
        num /=base;
    }while(num!=0);
    return ptr;
}

A.
It converts a number to a given base.
B. It converts a number to its equivalent binary.
C. It converts a number to its equivalent hexadecimal.
D. It converts a number to its equivalent octal.

4. 

Which of the following statements are correct about the program?

#include<stdio.h>

int main()
{
    unsigned int m[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
    unsigned char n, i;
    scanf("%d", &n);
    for(i=0; i<=7; i++)
    {
        if(n & m[i])
            printf("yes");
    }
    return 0;
}

A. It will put OFF all bits that are ON in the number n
B.
It will test whether the individual bits of n are ON or OFF
C. It will put ON all bits that are OFF in the number n
D. It will report compilation errors in the if statement.


© 2008-2010 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy