What will be the output of this code
//1. What will be the output of this code
#include<Stdio.h>
int main()
{
int x = 2;
if(x = 1){
printf("x is equal to 1");
}
else
{
printf("x is not equal to 1");
}
return 0;
}
a. error
b. x is equal to 1
c. x is not equal to 1
Ans. b. x is equal to 1, because when we write x = 1, that means we assign x =1 not asking (x==1) whether x is equal to 1 or not. so in if condition value of x becomes 1.
// 2. What will be the output of this code
#include<Stdio.h>
int main()
{
int x = 2;
if(x = 0){
printf("x is equal to 1");
}
else
{
printf("x is not equal to 1");
}
return 0;
}
a. error
b. x is equal to 1
c. x is not equal to 1
Ans : x is not equal to 1 because x = 2.
Comments
Post a Comment
Please do not enter any spam link in the comment box.