Josh technology
Company
Programming
Definition
#include
int main(void) {
int i=1024;
for(;i;i>>=1)
printf("jtg");
return 0;
}
Read Solution (Total 7)
-
- jtg will print 11 times as 1024 in binary 10000000000 and on one opt >>=1 then 1 present in msb will move to one digit to right and become 01000000000 then 00100000000 and so on.. till 00000000001
- 9 years agoHelpfull: Yes(6) No(0)
- jtg print 11 times, because 1024 represent in binary 0000 0100 0000 0000 now right shift by one, so for loop executed 11 time until i value become 0.
- 8 years agoHelpfull: Yes(2) No(0)
- Whenever there is a right shift by 1, the number gets divided by 2. For right shift by d digits, the number will be divided by 2^d. For eg- if the number is 20 and I right shift it by 2 digits, the answer will be 5.
For the given question, 1024 keeps on dividing by 2 until it has become 0. Therefore, it will be printed 11 times.
Refer- http://www.geeksforgeeks.org/interesting-facts-bitwise-operators-c/ - 8 years agoHelpfull: Yes(1) No(0)
- i think it will go to infinite loop
- 9 years agoHelpfull: Yes(0) No(4)
- This is not going to executed because there is no such directries included like STDIO.h or CONIO.h
and one thing more that..
for loop condition is in wrong place so this prog. is not going to execute - 9 years agoHelpfull: Yes(0) No(6)
- it it right shift so for each iteration i will shift right;
after 11 iteration loop will break; hence
ans is:11 - 8 years agoHelpfull: Yes(0) No(0)
- 10 loop will execute 10 times
- 6 years agoHelpfull: Yes(0) No(0)
Josh technology Other Question