

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of operator precedence and associativity in the c programming language. It covers various operators such as arithmetic, logical, and relational, and explains their position, associativity, and precedence. The document also discusses the use of parentheses to control the order of evaluation and the difference between prefix and postfix increment/decrement. Students of the university of notre dame taking the cse 20211 - fundamentals of computing i course will find this information useful for understanding the basics of c programming.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


CSE 20211 โ Fundamentals of Computing I โ Univ. of Notre Dame 09/09/ Read Chapter 3 Operator Precedence Different operators in C are +, , - , /, %,++, --. The latter two take either prefix or postfix form. Compound operators include +=, /=, =, - =, %=. For instance, i+=2 implies i = i + 2; Generally parenthesis can be used to control the precedence order in operators. Expressions in a parenthesis are evaluated first. When an expression contains more than one parentheses, the operators located in the innermost pair of parentheses have the highest precedence. For example, the + has the highest precedence in the statement below. x = ((a+b)-c/d); Also we cannot use two consecutive arithmetic operators in an expression between two variables, lest parentheses are used to separate them. For instance a-b should be written as a(-b) Operator Name # operands Position Associativity Precedence ( parentheses unary prefix L to R 1 ) parentheses unary postfix L to R 1
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. Logical operators !: logical not (unary) &&: logical and (binary) ||: logical or (binary) (condition)? exp1: exp When the C program encounters the ?: operator, it first evaluates the condition. If the conditions turns to be true, then exp1 is evaluated and used as the value of entire expression, if the condition is false the value is the result of evaluating exp2. max = (x > y)? x : y A B && || !A !B True True True True False False True False False True False True False False False False True True False True False True True False Relational Operators == !=
<
= <= Character variables The characters are defined using char. For example, char a; To initialize, a to a character value, do a = โyโ;