0

What will be the output of the questions?( C programming)

#include<stdio.h> void main(){ int a=4,b=2; if( a^b==printf("practice")) printf("sucess"); else printf("c"); }

11th Nov 2019, 10:23 AM
Diptansu das
Diptansu das - avatar
6 Answers
+ 1
Diptansu das put your a^b inside brackets like this (a^b) and the output would be practicec only.
11th Nov 2019, 11:52 AM
Avinesh
Avinesh - avatar
+ 1
Output will be practicec. Explanation: printf returns the length of output. In this case length of "practice". As you can see it is 8 characters long. 8 is not equal to a^b so it will result "c" . You have recently printed practice without a new line so the final output is practicec. However if you changed a^b to a*b it will result in "success" as 4*2 is 8. (edited. There was a mistake. I confused ^ as 'to the power of' as I was working with a lot of calculators lately rather than programming. :) It's fixed now)
11th Nov 2019, 10:40 AM
__IAS__
__IAS__ - avatar
+ 1
In if loop 1st it calculate xor of a and b (4^2=6) and second condition print success on screen and return no. Length of string ie 8 So 6==8 gives false therefore else part get executed Output : practicec
13th Nov 2019, 8:08 AM
Pooja
Pooja - avatar
0
Diptansu das Why don't you run it and see for yourself. If you don't understand something then post it.
11th Nov 2019, 10:25 AM
Avinesh
Avinesh - avatar
0
Actually the answer is not corr ct
11th Nov 2019, 11:45 AM
Diptansu das
Diptansu das - avatar
0
Output will be : practicec
12th Nov 2019, 7:22 AM
Eshant Aggarwal
Eshant Aggarwal - avatar