+ 2
Find out the output of the program
#include <stdio.h> int main() { int a=10, b=20; if(a=b) { printf("Easy"); } else { printf("Hard"); } return 0; }
11 Respostas
+ 4
Ajay Raj ..
If you want comparison with two values then use comparison operator "==" instead of the assignment operator "=".
For fex the error.
Change this comparison operator "==".
(`a==b`),instead of this(`a=b`)..
+ 2
DHEEVIKA SURESH
First decide Easy or Hard? because you have given 2 different answers.
+ 1
in you code you assign a to be not comparing it
your code should look like
#include <stdio.h>
int main()
{
int a=10, b=20;
//condition statement
if(a==b)
{
printf("Easy");
}
else
{
printf("Hard");
}
return 0;
}
0
Why not to get self in Code Playground?
0
If b is zero, only the else condition will be executed, otherwise the if condition as shown in the description.
The reason for this is due to a behavior called "Cohersion and Down casting" whereby a variable gets converted from a type to another possible type in this case from [int to boolean]
To prevent this, you have to use the right operator for example the equality checker's Operator (==) instead of the assignment operator (=)
0
Dear Ajay Raj
In this code, the header file stdio.h is included the preprocessor mixes the code of header file in our program file.
Now, the line of control goes to the int main() function and then the line of control jumps to the initialised variable where a=10 and b=20, Here a using (=) operator which is used to initialise the variable not for comparing variable.
Then, the line of control jumps to the if statement where a condition is given that if a is initialised to b then print "Easy" otherwise print "Hard" right.
Here, (a=b) means a is initialised to b where in a variable the value of b variable is put which is true.
Therefore, the output of this code is "Easy".
Output: Easy
Thanks for asking this question!
0
use '==' in line 5 for comparison of two values
0
Easy
0
Find out the output of the program
#include <stdio.h>
int main()
{
int a=10, b=20;
if(a=b)
{
printf("Easy");
}
else
{
printf("Hard");
}
return 0;
}
Output Easy
0
in you code you assign a to be not comparing it
your code should look like
#include <stdio.h>
int main()
{
int a=10, b=20;
//condition statement
if(a==b)
{
printf("Easy");
}
else
{
printf("Hard");
}
return 0;
} output Hard
0
Program 1
#include <stdio.h>
int main()
{
int a=10, b=20;
if(a=b)
{
printf("Easy");
}
else
{
printf("Hard");
}
return 0;
}
Program 2
#include <stdio.h>
int main()
{
int a=10, b=20;
//condition statement
if(a==b)
{
printf("Easy");
}
else
{
printf("Hard");
}
return 0;
}
Program 1 assign the value of b to a.
Program 2 compare tha value of a and b..