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

C and C++ Interview Questions

2. Which bit wise operator is suitable for turning off a particular bit in a number?

Ans:
The bitwise AND operator

In the following code snippet, the bit number 24 is reset to zero.
some_int = some_int & ~KBit24;

Ex - 1: .What will happen in these three cases?
if(a=0){
//somecode
}
if (a==0){
//do something
}
if (a===0){
//do something
}

Ans:

i)if conditional expression false so if block won't run.
ii)if a has zero then the if block will run otherwise won't run.
iii)if conditioal expression syntax error.

Ex - 2: What is the output?
main()
{
int i=_l_abc(10);
printf("%d\n",--i);
}
int _l_abc(int i)
{
return(i++);
}

Ans:
9

Explanation:
return(i++) it will first return i and then increments. i.e. 10 will be returned.

Ex - 3: What is the output?

main()
{
int i =0;j=0;
if(i && j++)
printf("%d..%d",i++,j);
printf("%d..%d,i,j);
}

Ans:
0..0

Explanation:
The value of i is 0. Since this information is enough to determine the truth value of the boolean expression. So the statement following the if statement is not executed. The values of i and j remain unchanged and get printed.


SLogix Student Projects
bottom