What Is Assignment Statement In C Language?

What Is Assignment Statement In C Language?

c language

Hello Programmer,

In the last blog, we studied user-defined data type and it's part but today we will discuss the assignment statement. We will discuss how we use an assignment statement and how to assign any value to a variable. 



Definition:

The statement in the C Programming language for carrying out computation and assign values to the variable is the assignment statement.

Example:        marks=90;

In the above example marks is a variable and we assign 90 marks to marks variable.

The form of an assignment statement is:    
                                                                   result=expression;
an expression is any value which we assign in the result variable.


One thing you must remember whenever you assigned a value to any variable the value must be of the same type as a variable.

The expression can be a single variable, a single constant or involve variable and constants combined by the arithmetic operators.

For example             i=3;
                                 sum=0.0;
                                 average=(a+b)/2;

You can also use rounded bracket() in matched pairs in expression to indicate the order of evaluation.      


Some Rule:

1) when you use two or more operand of integer type then the result is also integer type.

2) when you use two or more operand of float type then the result is also float type.

3) when you have a float variable and you try to assign integer value then the integer will be converted to an equivalent float before assignment to the float variable.

4) when you have integer variable and you try to assign float value then the float will be converted to an equivalent integer before assignment to the integer variable.


Whenever you assign any value to a variable then must ensure that that variable type and value type are same otherwise compiler set value according to variable type.

Example:            int num=3.5;

In this example, the num is an integer variable but you assign float value then compiler converts this value to an integer type and return the value of num variable is 3.

Example:            float num=3;

In this example, the num is a float variable but you assign integer value then compiler converts this value to a float type and return the value of num variable is 3.0.


Sharing Is Caring...

Comments :

Post a Comment