© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

1. Which bit wise operator is suitable for checking whether a particular bit is on or off?

Ans:

The bitwise AND operator.

Here is an example:

enum {
KBit0 = 1,
KBit1,

KBit31,
};

if ( some_int & KBit24 )
printf ( “Bit number 24 is ON\n” );
else
printf ( “Bit number 24 is OFF\n” );

Ex - 1: What will be printed as the result of the operation below:

main()
{
int x=10, y=15;
x = x++;
y = ++y;
printf(“%d %d\n”,x,y);

}

Ans: 11, 16

Ex - 2: What will be printed as the result of the operation below:
main()
{
int a=0;
if(a==0)
printf(“Tech Preparation\n”);
printf(“Tech Preparation\n”);

}

Ans: Two lines with “Tech Preparation” will be printed.

Ex - 3: .What will the following piece of code do

int f(unsigned int x)
{
int i;
for (i=0; x!0; x>>=1){
if (x & 0X1)
i++;
}
return i;
}

Ans: returns the number of ones in the input parameter X


SLogix Student Projects
bottom