C Programming - Bitwise Operators - Discussion
Discussion Forum : Bitwise Operators - Point Out Correct Statements (Q.No. 1)
1.
Which of the following statements are correct about the program?
#include<stdio.h>
int main()
{
unsigned int num;
int i;
scanf("%u", &num);
for(i=0; i<16; i++)
{
printf("%d", (num<<i & 1<<15)?1:0);
}
return 0;
}
Answer: Option
Explanation:
If we give input 4, it will print 00000000 00000100 ;
If we give input 3, it will print 00000000 00000011 ;
If we give input 511, it will print 00000001 11111111 ;
Discussion:
19 comments Page 2 of 2.
Vishal singh said:
1 decade ago
Sir I had executed this one and.
Answer is,
0100011101111000.
Since it is.
An conditional operator.
Asked to give 0.
Or 1 as a output.
Answer is,
0100011101111000.
Since it is.
An conditional operator.
Asked to give 0.
Or 1 as a output.
Kannan said:
1 decade ago
Why the program print binary value. What cmd?
Anu mishrs said:
9 years ago
No, this program is not giving output correctly only it give 1 or 0 due to conditional operator.
Bishal said:
8 years ago
What is %u in scanf?
Rvm said:
7 years ago
%u means? Please explain in detail.
Radhey said:
7 years ago
Unsigned means?
Vartika said:
7 years ago
I don't understand when I write %u in scanf, how is it behaving like %d?
Pavan said:
5 years ago
Unsigned means its a datatype like int but it is type modifier i.e,int has 2 bytes of memory means it stores values from -327768 to 32767 it is specified as %d similarly unsigned also has 2 bytes(size) from 0 to 65535 specifier %u.
Pavan anjali said:
4 years ago
If the int takes only positive values it is unsigned and signed means int takes both positive and negative numbers. As we know %c means char reads, %f means float reads.
Similarly %d means signed values read (both + answer -) and %u means unsigned values read-only + values.
Similarly %d means signed values read (both + answer -) and %u means unsigned values read-only + values.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers