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.
Shashank said:
6 years ago
= is the assignment operator. It will assign the value of b into a i.e. 1.55. Hence a and b are equal.
Ananth said:
9 years ago
How we get option A i.e "EQUAL" by using assignment operator. Can anyone explain with exact answer?
Sushil kumar said:
1 decade ago
Using assignment operator instead of equality operator will compile the code with a warning and answer will be option A.
Using equality operator will compile the code without any error and answer will be option B.
Using equality operator will compile the code without any error and answer will be option B.
Saravana said:
1 decade ago
If (a=b) means assignment, then where is the condition?
Menaka said:
1 decade ago
In this problem if(a==b) then what will be the answer?
Debashree said:
1 decade ago
Yah it's true.. @Girish Nischel
Girish nischel said:
1 decade ago
So whenever I write if (a=b) is the condition true?
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.
S.Arjun said:
1 decade ago
Yes its possible Thilagavathi.
Mani said:
1 decade ago
Ya possible. Thilagavathi.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers