C Programming Code Examples
C > Beginners Lab Assignments Code Examples
Operator precedence and Associativity Table in C Programming
/* Operator precedence and Associativity Table in C Programming */
Description Operator Associativity
Function expression ( ) Left to Right
Array Expression [] Left to Right
Structure operators -> Left to Right
Unary minus - Right to Left
Increment & Decrement -- ++ Right to Left
One's compliment ~ Right to Left
Pointer Operators & * Right to Left
Type cast (data type) Right to Left
size of operator sizeof Right to Left
Left and Right Shift >> <<
Arithmetic Operators
Multiplication operator, Divide by, Modulus *, /, % Left to Right
Add, Substract +, - Left to Right
Relational Operators
Less Than < Left to Right
Greater than > Left to Right
Less than equal to <= Left to Right
Greater than equal to >= Left to Right
Equal to == Left to Right
Not equal != Left to Right
Logical Operators
AND && Left to Right
OR || Left to Right
NOT ! Right to Left
Bitwise Operators
AND & Left to Right
Exclusive OR ^ Left to Right
Inclusive OR | Left to Right
Assignment Operators
= Right to Left
*= Right to Left
/= Right to Left
%= Right to Left
+= Right to Left
-= Right to Left
&= Right to Left
^= Right to Left
|= Right to Left
<<= Right to Left
>>= Right to Left
Other Operators
Comma , Right to Left
Conditional Operator ?: Right to Left
Assignment operators are used to assign the value, variable and function to another variable. Assignment operators in C are some of the C Programming Operator, which are useful to assign the values to the declared variables. Let's discuss the various types of the assignment operators such as =, +=, -=, /=, *= and %=. The following table lists the assignment operators supported by the C language: Simple assignment operator. Assigns values from right side operands to left side operand. Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand.
An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or false. Logical operators are commonly used in decision making in C programming. These operators are used to perform logical operations and used with conditional statements like C if-else statements.
An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides many types of operators. Except for Arithmetic and Logical Operator, there are some special Operators provided by C language which performs special operations and description of them summarized in the following table.
Relational Operators are the operators used to create a relationship and compare the values of two operands. For example, there are two numbers, 5 and 15, and we can get the greatest number using the greater than operator (>) that returns 15 as the greatest or larger number to the 5. Following are the various types of relational operators in C. Equal To Operator (==) is used to compare both operands and returns 1 if both are equal or the same, and 0 represents the operands that are not equal. Not Equal To Operator (!=) is the opposite of the Equal To Operator and is represented as the (!=) operator. The Not Equal To Operator compares two operands and returns 1 if both operands are not the same; otherwise, it returns 0.
The bitwise operators are the operators used to perform the operations on the data at the bit-level. When we perform the bitwise operations, then it is also known as bit-level programming. It consists of two digits, either 0 or 1. It is mainly used in numerical computations to make the calculations faster. We have different types of bitwise operators in the C programming language. The following is the list of the bitwise operators: Bitwise AND operator is denoted by the single ampersand sign (&). Two integer operands are written on both sides of the (&) operator. If the corresponding bits of both the operands are 1, then the output of the bitwise AND operation is 1; otherwise, the output would be 0.
The sizeof() operator is commonly used in C. It determines the size of the expression or the data type specified in the number of char-sized storage units. The sizeof() operator contains a single operand which can be either an expression or a data typecast where the cast is data type enclosed within parenthesis. The data type cannot only be primitive data types such as integer or floating data types, but it can also be pointer data types and compound data types such as unions and structs.
Arithmetic Operator is used to performing mathematical operations such as addition, subtraction, multiplication, division, modulus, etc., on the given operands. For example: 6 + 3 = 9, 5 - 3 = 2, 3 * 4 = 12, etc. are the examples of arithmetic operators. Let's discuss the different types of Arithmetic Operators in the C programming. Plus Operator is a simple Plus (+) Operator used to add two given operands. We can use Plus Operator with different data types such as integer, float, long, double, enumerated and string type data to add the given operand. The minus operator is denoted by the minus (-) symbol. It is used to return the subtraction of the first number from the second number. The data type of the given number can be different types, such as int, float, double, long double, etc., in the programing language.
A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it returns value 0. C program to demonstrate working
Picks a random value withing range low-high. Value returned seeds the rand() function. Print version information and exit. First seed the random function. Add line, to the array...
Finding maximum in general is comparison of two numbers. In C language we compare two quantities using relational operator. We using either > or < operator to compare 2 numbers
Instead of using Nested If Else. Lets combine 2 or more conditions together using Logical Operators. A number j1 among 3 numbers j1, j2 and j3 is said maximum if j1 > j2 and j1 > j3.