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

C and C++ Interview Questions

12. Why we need the bitwise opeartors ?

Ans:
Bitwise operators are used for bitwise comparssions.

Ex - 1: What is the output?

main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}

Ans:
45545

Explanation:
The arguments in a function call are pushed into the stack from left to right. The evaluation is by popping out from the stack. and the evaluation is from right to left, hence the result.

Ex - 2: Predict the output or error(s) for the following:

main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}

Ans:
1

Explanation:
Scanf returns number of items successfully read and not 1/0. Here 10 is given as input which should have been scanned successfully. So number of items read is 1.

Ex - 3: What is the output?

main()
{
int i=0;

for(;i++;printf("%d",i)) ;
printf("%d",i);
}

Ans:
1

Explanation:
Before entering into the for loop the checking condition is "evaluated". Here it evaluates to 0 (false) and comes out of the loop, and i is incremented (note the semicolon after the for loop).


SLogix Student Projects
bottom