[go: up one dir, main page]

0% found this document useful (0 votes)
58 views8 pages

C-Operators, Associativity and Precedence: A Group Report Submitted To: MR Sachin Dave

This document discusses C operators, associativity, and precedence. It defines what a C operator is and lists common types of operators like arithmetic, logical, and assignment. It also explains increment and decrement operators. Finally, it defines precedence as the order in which operators are evaluated and associativity as the order for operators of the same precedence, providing an example to illustrate these concepts.

Uploaded by

Priyanka Banthia
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views8 pages

C-Operators, Associativity and Precedence: A Group Report Submitted To: MR Sachin Dave

This document discusses C operators, associativity, and precedence. It defines what a C operator is and lists common types of operators like arithmetic, logical, and assignment. It also explains increment and decrement operators. Finally, it defines precedence as the order in which operators are evaluated and associativity as the order for operators of the same precedence, providing an example to illustrate these concepts.

Uploaded by

Priyanka Banthia
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

C-operators, associativity and precedence

A group report Submitted to: Mr Sachin Dave

By: Mansi Badheka Priyanka Banthia Akanksha Arora Chandni Baktarwala 2012-13

What is C?
C is a very flexible and powerful programming language originally designed in the early 1970s. It is famous as the language the UNIX operating system was written in, and was specially designed for this. However its use has now spread way beyond that field and it is currently very popular.

What is a C operator?
Operators are functions. Specifically, operators are special functions that are used to perform operations on data without directly calling methods each time. Common operators that you should be familiar with include +, -, *, /, <<, >>, and so on. All such operators can be used on primitive data types in C to achieve certain results. For example, we can use the + operator to add together two numeric values, such as ints, floats.

Types of operators
Arithmetic operators include the familiar addition (+), subtraction (-), multiplication (*) and division (/) operations. In addition there is the modulus operator (%) which gives the remainder left over from a division operation. a + b = 103 a - b = 97 a * b = 300 a / b = 33 a%b=1 Logical operators allow the program to make decisions based on multiple criteria, without using nested conditionals. They are known as shortcircuit because they skip evaluating their right argument if evaluating their left argument is sufficient to determine the overall value.

Assignment Operators: The assignment operator is + is used to assign a constant, value of variable or expression to a variable on its left. This is written as follows. Variable = expression; Many times it happens that the variable on left side of the assignment operator is repeated on right side also. In such situation the short-hand assignment operators provided iin C. for example X += 10; Where += is short-hand assignment operator. Hence, X += 10; Is short form of X = x+10;

Increment and Decrement


The ++(increment) and --(decrement) operator both are unary operators. The ++(increment) operator increments the integer variable by 1, while (decrement) operator decrements the integer variable by They are used only with integer variables. The ++ and are of two types: prefix and postfix. The ++m and m are examples of prefix increment and prefix decrement operators , respectively. Similiarly m++ and mare examples of postfix increment and postfix increment operators , respectively. ++m and m++ both increment the variable m by 1. In this case , both are not different as both increments m by 1. But when ++ operator is used with a variable in assignment or expression, then prefix and postfix makes difference.

Precedence and Associativity


" Precedence is: "the act or fact of preceding". So if something has precedence, it means that it goes before something else in a particular group. . Precedence in this case refers to which operators are evaluated BEFORE the others. Associativity Associativity determines the order in which operators of the same precedence are processed. For example, consider an expression: int x = 8 + 3 * 6 / 2

The arithmetic operators have left-to-right associativity, and multiplication and division have higher precedence than addition. So starting from the left of the equation, the highest precedence operator is multiplication, so 3 * 6 (= 18) is performed, then 18 / 2 (= 9) is performed. The expression is evaluated again from the left with the next level of precedence being addition, so 8 + 9 (= 17) is performed. Finally, the right side of the assignment operator is assigned to variable x

You might also like