# C Programming - Bitwise Operators - Discussion

### Discussion :: Bitwise Operators - Find Output of Program (Q.No.7)

7.

What will be the output of the program?

``````#include<stdio.h>

int main()
{
char c=48;
for(i=1; i<=5; i++)
{
}
return 0;
}
``````

 [A]. 12400 [B]. 12480 [C]. 12500 [D]. 12556

Explanation:

No answer description available for this question.

 Chinna said: (Jul 21, 2010) To increment five times in i and multiple by c and i and mask.

 Ashwin said: (Dec 8, 2010) Explanation. Please?

 Afsheen said: (Dec 16, 2010) Can anyone please explain this. ?

 Sai said: (Dec 22, 2010) Here mask means unsigned int i.e no negative values....mask 01 means 32 bit value.it is "00000000000000000000000000000001" c=48 it is written as "00000000000000000000000000110000" now "or" operation is performed then value becomes 49, mask=mask<<1 means it shifts 1 to 1-bit before then it becomes "000000000000000000000000000000010".now do o operation with 32digit binary bit of 48. Now value becomes 50.again mask=mask<<1 "00000100"(last 8bits)similarly do till for loop fails..then we get values as 49,50,52,56,48....the %c converts int to char thatmeans it prints the ASCII values of these nunbers ASCII of 48=0,49=1,50=2......57=9..replace the values u get o/p as 12480......

 Samatha said: (Mar 21, 2011) Well. Thanku.

 Sneha said: (May 5, 2011) Thanks sai.

 Sowmya said: (May 7, 2011) Thanks a lot Sai!! :) :)

 Yamini said: (Jul 17, 2011) I cant understand that left shift operation "<<" Can anyone pls explain me n make me clear

 Kirubhakaran said: (Jul 29, 2011) It is nothing but shifting the binary values to left !! In case if u have a binary number 11001101, after you left shit this binary number by 1 digit, you will have 10011010.. that is, the first digit is removed and a he remaining elements are written and a zero is appended at last...

 Arun said: (Jul 30, 2011) #include int main() { char c=48; int i, mask=01; for(i=1; i<=5; i++) { printf("%c", c|mask); mask = mask<<1; } return 0; } Please explain above the program.

 Jayadeep said: (Aug 6, 2011) Hi @arun Here c is assigned 48 so its binary value is 110000 mask is assigned 1 i.e 00000001 So while running the for loop first time c|mask means bitwise operation is performed so each bit is manupulated So c|mask gives 00110000 00000001 -------- 00110001 = 49 But we are printing using %c so the ascii character corresponding to this is printed So 1 is printed then the mask is left shifted so it becomes 00000010 so if we perform or operation we will get 50 which is equal to 2 like this it prints 12345

 Pritam said: (Aug 19, 2011) At 5th loop mask=01000 and 48 or 01000 gives 64 then how it comes 48 again?

 Razia said: (Aug 19, 2011) It is supposed to print c|mask, instead it is printing only the value of mask.

 Razia said: (Aug 21, 2011) Why it is printing only mask value?

 Jhansi said: (Sep 3, 2011) Thanks alot sai.

 Pawan Mishra said: (Sep 9, 2011) Thanks sir realy understoodable answer. Thank you so much.

 Adi said: (Sep 13, 2011) Razia, its not printing mask. Its printing 49 as 49-48=1 then 50-48=2 then 52-48=4 and then 48-48=0 on it prints 12480.

 Poobal said: (Sep 13, 2011) Please any one can explan this program clearly ?

 Bhavana said: (Sep 13, 2011) Well said. For clearing my confusion.

 Lavanya Duddu said: (Mar 15, 2012) << means Leftshoft operations lets take number 2 (0010) if you do left shift operation it becomes 0100(4) so short cut for << operation is just multiply by two.

 Rohit said: (Apr 7, 2012) @Sai. Thank you very nuch.

 Ravi said: (May 2, 2012) Thanks sai.

 Mun said: (May 10, 2012) Left shift << is Multiply by power of 2. So therefore ,12480 consecutively 5 times !!

 Ajit Yadav said: (May 25, 2012) For those having problem in 5th loop. C = 48 = 110000. Mask= 16 = 010000. Perform or operation and you will get 110000 i.e. 48. And 48 in ascii is '0'.

 Bhavesh said: (May 30, 2012) "c|mask" what does it mean?

 Pramod Soni said: (Jul 7, 2012) Thank you very much Amey.

 Vraj Shah said: (Jul 8, 2012) Thanks amey :).

 Ruella said: (Aug 18, 2012) Amey that was impressive and neat! thanks

 Gayatree Verma said: (Aug 24, 2012) Thanks amey and sai.

 Nithy said: (Aug 27, 2012) Doesn't masking mean AND operation?

 K.Harika said: (Aug 31, 2012) Please give the correct answer properly.I can't understand this program.

 Sanjana said: (Sep 7, 2012) Thanks amey your explanation is very good.

 Thirumalai Kumarasamy said: (Apr 4, 2013) int main() { char c=48; int i, mask=01; for(i=1; i<=5; i++) { printf("%c", c|mask); mask = mask<<1; } return 0; } Yes I understood clearly. On first time "c|mask" 48 into binary 110000 000001 = 110001 (49 in ascii = 1 next line left shift of mask<<000001 = 000010). 2) 110000 or 000010 = 110010(50=2 in ascii). 3 110000 or 000100 = 110100(52=4 in ascii). 4)110000 or 001000 = 110010(56=8 in ascii). 5)110000 or 010000 = 110000(48=0 in ascii). Then print one by one 12480.

 Ginna said: (May 30, 2013) How to find binary values during interview tests?

 Kaveri said: (Sep 24, 2013) How to calculate ASCII value?

 Sachin Behera said: (Jan 31, 2014) How can we know quickly the ASCII value ?

 Sagalakala Vallavan said: (Jan 31, 2014) 48 ascii value 0. 49 - 1. 50 - 2. 52 - 4. 56 - 8. Left shift 0.

 Ramkumar said: (Jul 30, 2014) Left shift operation like an multiples of 2. For ex. If we left shift of 2 at one time the result will be 2*2 = 4. Similarly, right shift operation like an divide by 2. For ex. If we right shift of 2 at one time the result will be 2/2 = 1.

 Jasss said: (Aug 11, 2014) #include int main() { int i=4, j=8; printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j); return 0; } Can anyone tell me how this program will work step by step?

 Tanu Priya Saxena said: (Aug 21, 2014) Mask is declared 01. It should be read as an octal since it is starting with 0.

 Pankaj said: (Oct 3, 2014) #include int main() { char c=48; // Integer value of c is 48, which belongs to char '0'; int i, mask=01; // same as mask=1; printf("%c\n",c); for(i=1; i<=5; i++) { printf("%d %d\n",c,mask); // displaying the integer values of c and mask printf("%c\n", c|mask); mask = mask<<1; } return 0; } Since the bitwise operator is defined on the integer values, i.e a|b, where a and b are integers. In this problem, we calculate bitwise OR on integer values and then convert it back to char as the output is required as "%c". Try the above code, Hope this will help.

 Priyanka said: (Oct 5, 2014) For last loop. i=5; 0011 0000 |0001 0000 =0100 0000 its 64. how come its 48?

 Venu Gopal said: (Oct 13, 2014) There is nothing in left shift(<<) and right shift(>>) operators. Let us discuss in simple manner. 1. Left Shift operator(<<):- For example if the left shift operator in this manner i<>). i>>n=i/(2^n). Ex::2<<3=2*(2^3)=2*(2*2*2)=2*(8)=16.(ans). Ex::2>>3=2/(2^3)=2/(2*2*2)=2/(8)=0.(ans).

 Mukunda Saini said: (May 27, 2015) I think OR operation means 1+1 = Sum 0 and carry 1. So carry will add to the next position. 110000+010000 = 1000000. Please tell me how to get last one 48?

 Jitendra Malviya said: (Aug 15, 2015) Mask is assigned 1 i.e. 00000001, means? I am not getting point.

 Swati said: (Aug 31, 2015) How 48 ASCII is 0? Please anyone explain it?

 Mukund said: (Sep 26, 2015) 48- ASCII value is 0. 48 | 01 = 49 value is 1 printed. Mask << 1 means (mask) 1*2^(1) = 2. Again 48|2 value 2 will printed. Mask = 2*2 = 4. 48|4 then 4 is printed after 8 and 0 are printed.

 Prajkta said: (Jan 19, 2016) Please detail explanation this program.

 Jitendra Vaishnav said: (Jul 25, 2016) @Mukunda Saini. OR operation doesn't means sum its logical or operation. Where 1 OR 1 is 1. So there will be no carry on next position.

 Rohit Singh said: (Jul 25, 2016) Thanks, @Sai & @Thirumalai.

 Vasundhara said: (Aug 21, 2016) Thanks, easy explanations @Amey.

 Shravan said: (Jan 19, 2017) @Sai. Very good explanation. Thank you.

 Hamilton said: (Mar 3, 2017) Thanks for all your explanation.

 Merlin said: (Jun 10, 2017) Good Explanation, thanks @Amey.

 Komal said: (Jul 11, 2017) Very nice, Thank you all.

 Dinesh said: (Aug 24, 2017) Can we assign an integer value in char data type?

 Maheswari said: (Oct 25, 2017) Yes, you can assigned integer value in char data type. For example : char i=21; printf("%c",i); //it will not print anything and no error; printf("%d",i);//it will print the value of I;

 Jayesh said: (Dec 24, 2017) Thanks, nice explanation @Amey.

 Santhosh Kumar said: (Jan 5, 2018) @Priyanka. "or" operation performed is not like 1+0=0, 1+1=0, 0+0=0 it is performed using truth table like; OR truth table Input Output 1 - 1 1 1 - 0 1 0 - 1 1 0 - 0 0 therefore the operation on 0011 0000 0001 0000 _________ 0011 0000 ________ which is equal to 48 whose ascii value is 0. what you have done is 11 0011 0000 0001 0000 ________ 0100 0000 _________ So or operation is done using truth table conditions.

 Zhongshunchao said: (Mar 7, 2018) 0011 0000 == 48 ---0. 0011 0001 == 49 ---1. 0011 0010 == 50 ---2. 0011 0100 == 52 ---4. 0011 1000 == 56 ---8. 0011 0000 == 48 ---0.

 Zhongshunchao said: (Mar 7, 2018) 0011 0000 == 48 ---0 0011 0001 == 49 ---1 48|0001. 0011 0010 == 50 ---2 48|0010. 0011 0100 == 52 ---4 48|0100. 0011 1000 == 56 ---8 48|1000. 0011 0000 == 48 ---0 48|0000.

 Neha said: (May 10, 2018) Thanks @Amey.

 Ruhee said: (May 22, 2018) Thanks @Jayadeep.

 Padma said: (Jul 21, 2018) Thank You @Sai.

 Dhivya said: (Oct 2, 2018) How to find ascii value manually? Please explain.

 Varsha said: (Aug 9, 2019) Thanks @Sai, @Jayadeep and @Amey.

 Avjagjeet said: (Apr 20, 2020) @Sai. As per my knowledge, the explanation is. itr 1 0001 | 110000 => 49 => ifsc printing %c so convert int to char by ifsc i.e. 1. itr 2 0010 | 110000 => 50 => ifsc printing %c so convert int to char by ifsc i.e. 2. itr 3 0100 | 110000 => 110100 => 52 => ifsc printing %c so convert int to char by ifsc i.e. 4. itr 4 00001000 | 110000 => 111000 => 56 => ifsc printing %c so convert int to char by ifsc i.e. 8. itr 5 00010000 | 110000 => 110000 => 48 => ifsc printing %c so convert int to char by ifsc i.e. 0.