Wednesday, 23 January 2019

Chapter:Operation and Expressions(part-2)

Question: Explain precedence and associative of operator with suitable example[wbut 2005,2014,2017]

Operator precedence

Operator determine the order in which expression are evaluated. this is some case can determine the overall value of expression. in general increment and decrement are  evaluated before automatic operation, arithmetic expression are evaluated before comparisonAnd comparison are evaluated before logical expression. lastly assignment expression are  elevated.

Parenthesis, braces


Arithmetic operator

Arithmetic operator

Shift operator

Relational operator

Relational operators

Logical operator

Conditional operators

Arithmetic assignment operator

[ ],(),{}




<< >>






Operator associative

Associativity Rules determine the grouping of operands and operator in
expression with more than one operator of the same precedence. when the
operation in expression all have the same presidents rating. the associativity rules determine the order of operation. foremost operators, the evolution is done left to right.
Example d=a+b-c;
Hair addition and subtraction have the same precedence rating and so A and B are added first, then from the sum she is subtracted. parentheses can be used to over rule the default associativity.
Example d=a+(b-c ).
Question:-What is ternary operator?(wbut 2007,2009,2014,2015)
What is conditional operators?

Answer: The conditional operator container condition followed by two statements all values.
If condition is true the first statement is executed otherwise the second statement is executed.
The conditional operators is called ternary operator because sometimes the conditional operators takes three arguments.

The symptoms of conditional expression is:-

Condition? (Expression1) : ( expression2);

Two expression are separated by semicolon. if the condition is true expression one get  evaluated otherwise expression to evaluated. the condition is always written before the? Mark.
Example /* find the greatest among the two numbers using conditional operator or ternary operator*/
void main()
int a,b,max;
printf("Enter the values for a and b:");
scanf("%d%d", &a,&b);
max=(a>b)? a:b;
printf("Greater of %d and %d is %d\n",a,b,max);
Output:Enter the values for a and b: 54 45
Greater of 54 and 45 is 54.

No comments:

Post a Comment

Basic Electronics Engineering (EC101)

Basic Electronics Engineering (EC101)