Assignment Statement
The statement that is used to assign a value to a variable is called assignment statement. The value which is assigned to a variable can be a value returned by an expression or value of a variable or constant value. A constant string cannot be assigned to a string variable through assignment statement.The general form of assignment statement is as follows;
variable = expression ;
Assignment Operator
In C-language, the equal sign (=) is called the assignment operator. It is used to assign the value of expression to the variable. The expression on the right side of the assignment operator is evaluated first and the result is then assigned to the variable on the left side of the operator.
For example;
c = a + b;
In the above assignment statement, the expression "a + b" is evaluated first. The value returned by this expression is assigned to variable 'c' by the operator "=".
Rvalue
The Rvalue is an operand that can be written on the right side of the assignment operator (=). It can be constant value, a variable or an expression. For example,
x = 6;
x = y;
Lvalue
The Lvalue is an operand that can be written on the left side of the assignment operator (=). It must be a variable. In the above example, 'x' is written as Lvalue.
The Lvalue can be used as Rvalue but the reverse cannot be true. For example, a constant value can be used as Rvalue but it cannot be used as Lvalue.
EXAMPLE in C
#include<stdio.h>
#include<conio.h>
void main()
{
int a , b , sum ;
a = 12 , b = 45 ;
int a , b , sum ;
a = 12 , b = 45 ;
sum = a + b ;
printf ( " sum = %d ", sum ) ;
}
EXAMPLE in C++
#include<iostream>
usingnamespace std;
int main()
{
int a , b , sum ;
a = 12 , b = 45 ;
sum = a + b ;
cout << " Sum = " << sum ;
return 0;
}
Output of the program
Sum = 57
|
No comments:
Post a Comment
Thanks For Visiting Here...!! I will Reply you as soon as possible.