"On your mark, get set go..."
Captain of a cricket team is as good as his team. If team is not good enough, captain alone can't do much. Same is C programming. Unless you know the instructions that it offer, you can hardly write a good program.
Types Of Instruction
a) Type Declaration Instruction
This instruction is used to declare the type of variables used in a C program . Any variable used in the program must be declared before it is used in any statement. The type declaration statement is written as the beginning of main() function.
Example - int, float, char name etc.
b) Arithmetic Instruction
b) Arithmetic Instruction
Am arithmetic instruction in C consists of a variable name on the left hand side of equal and variable name and constant on the right hand side of equal. The variable and constant on the right hand side of equal are connected by arithmetic operators like +,-,* and /.
Example : int ad
float kot, deta,alpha, beta, gamma;
ad=3200;
kot=0.0056;
deta=alpha*beta/gamma+3.2*2/5;
Here;
*, /, -, + are arithmetic operators.
= is the assignment operator.
kot, deta, alpha, beta, gamma are real variables.
Integer And Float Conversions
In order to to effectively develop C program, it will be necessary to understand the rules that are used for the implicit conversion of floating point and integer value in C. These are mentioned below.
a) An arithmetic operation between an integer and integer always yields an integer result.
b) An operation between a real and real always yields a real result.
c) An operation between an integer and real always yields a real result. In this operation, the integer is first promoted to a real and then the operation is performed. Hence the result real.
I think a few practical example shown :
Operation Result Operation Result
5/2 2 2/5 0
5.0/2 2.5 2.0/5 0.4
5/2.0 2.5 2/5.0 0.4
5.0/2.0 2.5 2.0/5.0 0.4
Operator Precedence -
When an expression contains two or more operators, normal operator precedence rules are applied to determine the order of evaluation. If two operators have different levels of precedence, the operator with the highest precedence is evaluated first. For example, multiplication is of higher precedence than addition, so the expression 2+3*4 is evaluated as 3 * 4 = 12 2 + 12 = 14 The evaluation order can be explicitly controlled using parentheses; e.g., (2+3)*4 is evaluated as 2 + 3 = 5 5 * 4 = 20 Operators in the previous table are presented in groups from highest to lowest precedence.Operator Associavity -
If two operators in an expression have the same precedence level, they are evaluated from left to right or right to left depending on their associavity. For example, additions associavity is left-to-right, so the expression 2+3+4 is evaluated as (2+3)+4. In contrast, the assign operators associavity is right-to-left; so the expression x=y=z is evaluated as x=(y=z).Category | Operator | Associavity |
---|---|---|
Postfix | () [] -> . ++ - - | Left to right |
Unary | + - ! ~ ++ - - (type)* & sizeof | Right to left |
Multiplicative | * / % | Left to right |
Additive | + - | Left to right |
Shift | << >> | Left to right |
Relational | < <= > >= | Left to right |
Equality | == != | Left to right |
Bitwise AND | & | Left to right |
Bitwise XOR | ^ | Left to right |
Bitwise OR | | | Left to right |
Logical AND | && | Left to right |
Logical OR | || | Left to right |
Conditional | ?: | Right to left |
Assignment | = += -= *= /= %=>>= <<= &= ^= |= | Right to left |
Comma | , | Left to right |
Note - Postfix increment/decrement have high precedence, but the actual increment or decrement of
the operand is delayed (to be accomplished sometime before the statement completes execution). So in
the statement y = x * z++; the current value of z is used to evaluate the expression (i.e., z++ evaluates
to z) and z only incremented after all else is done.