What is the difference between = and == in C?
Answers were Sorted based on User's Feedback
Answer / anita sachdeva
= operator in C language is used to assign the value of
right-hand side value/variable/expression to the left hand
side variable.
== operator in C/C++ language is used to check the value of
left hand variable/expression with the right hand
variable/expression. whether the two values are equal or
not. It returns true if these are equal else it will return
false.
| Is This Answer Correct ? | 312 Yes | 21 No |
Answer / sunita
1. First of all = is a assignment operator and == is a
comparision operator
2.= give you the same vale like x=y means if x=5 then y=5
on the otehr hand if x==y then it will give you the true or
false
eg if x==5
y==5
then return true
| Is This Answer Correct ? | 98 Yes | 16 No |
Answer / srabani
= it is used to assign a variable
== it is used to comparison of vale
| Is This Answer Correct ? | 56 Yes | 10 No |
Answer / chandan
= Assignment Operator
== Comparision Operator
One Intresting Difference between these two is in the =
operator the left side can not be a const, while in == we
can place Const in either side.
eg. x = 5 //correct
5 = x // Incorrect
but X == 5 // CORRECT
5 == X // Correct and Preffered to use left value
as constant to avoid the unwanted bug.
| Is This Answer Correct ? | 46 Yes | 7 No |
Answer / k.s. karthick prabu
= is the assigment operator
=is used to copy
ex:
a=5 means, copy just that value for 'a'.
== is comparision operator
ex:
#include<stdio.h>
void main()
{
int a;
scanf("%d",&a);
if(a==5)
printf("welcome");
else
printf("if the is not equal to 5");
}
| Is This Answer Correct ? | 37 Yes | 7 No |
Answer / mallika
= is used to assign the values to the variables.
Eg:- int a=5,b;
b=a;
== is used for comparison purpose.
Eg:- if(a==b)
continue;
| Is This Answer Correct ? | 31 Yes | 6 No |
Answer / vaibhav meena
= is assignment operator. It is used to assigne a value to a
variable.
and == is a comparison operator is is used to compare to values.
| Is This Answer Correct ? | 27 Yes | 5 No |
Answer / nila
= this is assignment operator.it is used to assign a
variable to variable and assign a value to variable.
== this is comparison iperator.it is used to compare any
two variable and values.
| Is This Answer Correct ? | 16 Yes | 2 No |
Answer / sagar pce
1.> = is an Assignment operator
whereas == is an Comparision or Equality operator
2.> If we go for the = operator the value will be same for
both side i.e; X=Y
for eg. if X=7 then Y=7
but when we go for the == operator the value will show the
result as a true or false
for eg. if X==7 and Y==7
then it return TRUE
| Is This Answer Correct ? | 13 Yes | 3 No |
Program to check whether a word is a sub-string or not of a string typed
What is pure virtual function?
What are containers in c++?
What will happen if when say delete this ?
How can you force instantiation of a template?
class Foo { const int x; protected: Foo(int f); ~Foo(); }; Foo f; Referring to the sample code above, why will the class declaration not compile? a) The variable x is const. b) The destructor is protected. c) The destructor is not public. d) The constructor is protected. e) There is no default constructor.
Can you Mention some Application of C/C++?
What do you understand by a pure virtual member function?
write a program that reads in a file and counts the number of lines, words, and characters. Your program should ask the user to input a filename. Open the file and report an error if the file does not exist or cannot be opened for some other reason. Then read in the contents of the file and count the number of lines, words, and characters in the file. Also print additional information about the file, such as the longest and shortest words, and longest and shortest lines. For simplicity, we define a word to be one or more characters ending with white space (a space, tab, carriage return, etc.). Functions for checking the types of characters can be found in the ctype.h header file, so you want to include this header file in your program. For example, the sentence below could be all that is in a file. This sentence IT 104 is taught in C++. has 32 characters, one line, and six words. The shortest line is 32 characters. The longest line is 32 characters. The shortest word is 2 characters. The longest word is 6 characters
Can I learn c++ as my first language?
What do you mean by public protected and private in c++?
What are abstract data types in c++?