Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.


Please wait...

C Programming :: Declarations and Initializations

6. What does the following 'C' program do ?

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

Answer: Option B

Explanation :

Here integer (unsigned) is assumed as 2 bytes so that for loop is till 16 i.e (2byte = 16 bits.)

As unsigned integer so user is expected to enter positive number.

statement in printf (num << i & 1 << 15)? 1:0 is used to convert decimal to binary equivalent.

in the above statement below things has been used.

<< ----> left shift

& -----> And operator

? : ------> trinery operator

Ex: if the number is 10 and its binary equivalent 1010 or (00000000000001010 in 16 bit)

the printf statement will be

for i = 0

(10 << 0 & 1 << 15)>?1:0

for i = 1

(10 << 1 & 1 << 15)>?1:0

similarly for i = 2, 3, 4 , ---- 15

Post Your Answer Here:     

q4i-reply-your-answer Reply     |    Rate This: +0 -0      |     Report     |     To Reading List



Report Error

Please Login First Click Here