Assignment And Conditional Operators.
Hello Programmer,
Today we will discuss Assignment and Conditional Operators these operators are most important in a programming language. In the last blog, we studied relational operators and logical operators today we will discuss 2 more operators.
1) Assignment Operators:
Assignment operators are those operators which help to assign any value into the variable. In c language we use "=" equal sign as assignment operators.
For Example:
i=5;
x=33;
sum=a+b;
when you use the equal sign in this way, the equal sign should be read as "gets". In c language, you can use equal sign as "shorthand" assignment operators in addition.
For Example:
x+=1; is equivalent to x=x+1;
x+=y+1; is equivalent to x=x+y+1;
In c language, there are many shorthand assignment operators.
(1) += (2) -= (3)*= (4)/= (5) %=
2) Conditional Operators:
We used conditional operators for checking a condition and we select a value depending on the value of the condition.
Syntax: variable=(condition)?value1:value2;
If conditions are true then value1 is evaluated and become the value of a variable and if the condition is false then value2 will become the value of variable.
Example: sum=(a>b)?a:b; which is equal to:
if(a>b)
sum=a;
else
sum=b;
Sharing Is Caring...
Comments :
Post a Comment