Professional Documents
Culture Documents
Name: - Maddi Abhilash Class: - 1mca REG NO: - 1947234 C Programming Cia 1
Name: - Maddi Abhilash Class: - 1mca REG NO: - 1947234 C Programming Cia 1
Associativity of Operators
Associativity is concept by which we resolve the concept between priorities of operators.
Associativity is used when two operators of same precedence appear in an expression. Associativity
can be either Left to Right or Right to Left.
For example: - Multiplication and Division have same priority and both have left to right
associativity then how can we resolve this problem.
Rules:-
1) Left to right associative means that left operand must be unambiguous (non-confusion) i.e.
it must not involve any further sub expression evaluation.
2) Right to left associative means that right operand must be unambiguous (non-confusion)
i.e. it must not involve any further sub expression evaluation.
As both enjoys left to right associativity, first * operations would be evaluated as its left part of
unambiguous.
main()
int x;
x=10/(5*2);
printf("value of x is %d",x);
C PROGRAMMING ASSIGNMENT 3
Output:-
Priority of Operators
Operator precedence determines the grouping of terms in an expression and decides how an
expression is evaluated. Certain operators have higher precedence than others.
For example, the multiplication operator has a higher precedence than the addition operator.
Precedence of operators comes into picture when in an expression we need to decide which
operator will be evaluated first. Operator with higher precedence will be evaluated first.
Example:
2+3*5
#include<stdio.h>
int main()
int a,b,c,d,e;
a=10,b=5,c=5,d=10;
e=a/b+c+d;
Output:-
C PROGRAMMING ASSIGNMENT 5
C - Type Casting
Implicit Type Conversion
Implicit type casting means conversion of data types without losing its original meaning. This type
of typecasting is essential when you want to change data types without changing the significance of
the values stored inside the variable.
Implicit type conversion happens automatically when a value is copied to its compatible data type.
During conversion, strict rules for type conversion are applied. If the operands are of two different
data types, then an operand having lower data type is automatically converted into a higher data
type. This type of type conversion can be seen in the following example.
}
C PROGRAMMING ASSIGNMENT 6
Output:-
The type conversion performed by the programmer by posing the data type of the
expression of specific type is known as explicit type conversion. The explicit type
conversion is also known as type casting.
(data_type)expression;
where, data_type is any valid c data type, and expression may be constant,
variable or expression.
#include<stdio.h>
int main()
int a,b;
float x;
C PROGRAMMING ASSIGNMENT 7
a=10;
b=4;
x=a/(float)b;
printf("Answer=%f\n", x);
return 0;
Output:-