Assignment statement assigns a value to a variable. Assignment means to set a value to a variable.
An Assignment statement is a statement that is used to set a value to the variable name in a program. It stores a value in the memory location which is denoted by a variable name.
Assignment statements initialize or change the value stored in a variable using the assignment operator =. An assignment statement always has a single variable on the left hand side. The value of the expression on the right of the = sign is stored in the variable on the left.
Syntax:
The symbol used in an assignment statement is called assignment operator. The symbol is ‘=’.
The Basic Syntax of Assignment Statement in C is:
variable = constant/variable/expression ;
where,
variable = variable name
expression = it could be either a direct value or a math expression/formula or a function call.
The expression on the right hand side of the assignment statement can be:
· An arithmetic expression;
· A relational expression;
· A logical expression;
· A mixed expression.
Examples of assignment statements,
a = b ; /*a is assigned the value of b */
a = 5 ; /* a is assigned the value 5*/
b = c+5; /* b is assigned the value of expression c+5 */
FAQ:
- What is an assignment statement in C?
- What is an assignment statement example?
- How do you write an assignment statement?