488 views

2 Answers

Best answer
2 votes
2 votes

All C++ operators have two attributes. These two attributes are known a precedence and associativity.

Since you've asked about Precedence- So Precedence refers to the rank of an operator.

Like in mathematics we have BODMAS where the highest precedence is given to Bracket and lowest precedence is given to Subtraction. 

Similarly, C++ has an order of precedence and it decides how an expression will be evaluated. For example, we have an expression 

2 * 5 + 3  

Therefore, the above expression can be evaluated in two ways, first (2*5)+3 = 13 and second 2*(5+3) = 16 .

So we have two different answers, and in C++ first one is correct and * has higher precedence than +

Here's the table for precedence, Hope it helps. :)

selected by
1 votes
1 votes
precedence rules tells about the order of evaluation of an expression.For some expressions like 2+3*4 you can evaluate them in two ways either(2+3)*4 or 2+(3*4) precedence rules  describe you the correct way of evaluating an expression

Related questions

0 votes
0 votes
1 answer
1
iarnav asked May 27, 2017
245 views
What are structured languages and what are their major features?
0 votes
0 votes
1 answer
2
iarnav asked May 27, 2017
271 views
Consider a pointer declaration int i=10,*p; p=&x;Is p – – ; a valid statement, justify? explain in as simple way as possible.
0 votes
0 votes
1 answer
3
iarnav asked May 27, 2017
244 views
What is the main difference between array of pointers and pointer to an array? please Explain with the help of a program/example
0 votes
0 votes
0 answers
4
iarnav asked May 27, 2017
178 views
how to Write a program to search a key string in a array of strings,if a key string is found then return its position and then replace that key string by any string using...