C Programming - Expressions - Discussion
Discussion Forum : Expressions - Point Out Correct Statements (Q.No. 1)
1.
Which of the following statements are correct about the below program?
#include<stdio.h>
int main()
{
float a=1.5, b=1.55;
if(a=b)
printf("a and b are equal\n");
else
printf("a and b are not equal\n");
return 0;
}
Discussion:
15 comments Page 1 of 2.
Vipin said:
2 decades ago
Main reason behind this answer is that assignment operator is right associative so it will alocate the value of b to a which is non zero so it will remain true hence the answer will b "a and b are equal";
Gandi said:
2 decades ago
In if condition how we use single equal symbol
Chandru said:
2 decades ago
Is it possible to use assignment operator(=) in if condition instead of using equality operator(==) ? Explain me the concept how can we use like this.
Mahesh said:
2 decades ago
= Operator Means assign value to right side value to left side.
== Operator can be compare value if both value are equal or not.
So Answer is "a and b are equal".
== Operator can be compare value if both value are equal or not.
So Answer is "a and b are equal".
Thilagavathi said:
2 decades ago
Is it possible to use assignment operator in if statement ?
Mani said:
1 decade ago
Ya possible. Thilagavathi.
S.Arjun said:
1 decade ago
Yes its possible Thilagavathi.
Abdul said:
1 decade ago
Because if (a=b) it is a assignment operator so condition will true.
If you want compare if (a==b) then it will print Option B.
If you want compare if (a==b) then it will print Option B.
Girish nischel said:
1 decade ago
So whenever I write if (a=b) is the condition true?
Debashree said:
1 decade ago
Yah it's true.. @Girish Nischel
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers