###### Programming-for-Output-Problems

October 6, 2023###### UGC NET CS 2014 Dec – paper-3

October 6, 2023# Programming-for-Output-Problems

Question 29 |

The for loop

for (i=0; i<10; ++i)

printf(“%d”, i&1);

prints:

for (i=0; i<10; ++i)

printf(“%d”, i&1);

prints:

0101010101 | |

0111111111 | |

0000000000 | |

1111111111 |

Question 29 Explanation:

The loop will execute for 10 times, from “i” value 0 to 9

“&” is bitwise AND operator.

For a given i=0 , the value is 0&1 is 0000 & 0001 which is 0

i=1, 0001 & 0001 which is 1

i=2 , 0010 & 0001 which is 0

i=3 0011 & 0001 which is 1

i=4 , 0100 & 0001 which is 0

i=5 0101 & 0001 which is 1

i=6 , 1100 & 0001 which is 0

i=7 0111 & 0001 which is 1

i=8 , 1000 & 0001 which is 0

i=9 1001 & 0001 which is 1

So the output is 0101010101(from i=0 to 9)

“&” is bitwise AND operator.

For a given i=0 , the value is 0&1 is 0000 & 0001 which is 0

i=1, 0001 & 0001 which is 1

i=2 , 0010 & 0001 which is 0

i=3 0011 & 0001 which is 1

i=4 , 0100 & 0001 which is 0

i=5 0101 & 0001 which is 1

i=6 , 1100 & 0001 which is 0

i=7 0111 & 0001 which is 1

i=8 , 1000 & 0001 which is 0

i=9 1001 & 0001 which is 1

So the output is 0101010101(from i=0 to 9)

Correct Answer: A

Question 29 Explanation:

The loop will execute for 10 times, from “i” value 0 to 9

“&” is bitwise AND operator.

For a given i=0 , the value is 0&1 is 0000 & 0001 which is 0

i=1, 0001 & 0001 which is 1

i=2 , 0010 & 0001 which is 0

i=3 0011 & 0001 which is 1

i=4 , 0100 & 0001 which is 0

i=5 0101 & 0001 which is 1

i=6 , 1100 & 0001 which is 0

i=7 0111 & 0001 which is 1

i=8 , 1000 & 0001 which is 0

i=9 1001 & 0001 which is 1

So the output is 0101010101(from i=0 to 9)

“&” is bitwise AND operator.

For a given i=0 , the value is 0&1 is 0000 & 0001 which is 0

i=1, 0001 & 0001 which is 1

i=2 , 0010 & 0001 which is 0

i=3 0011 & 0001 which is 1

i=4 , 0100 & 0001 which is 0

i=5 0101 & 0001 which is 1

i=6 , 1100 & 0001 which is 0

i=7 0111 & 0001 which is 1

i=8 , 1000 & 0001 which is 0

i=9 1001 & 0001 which is 1

So the output is 0101010101(from i=0 to 9)

Subscribe

Login

0 Comments