Sunday, May 16, 2021

OPERATORS IN C PRGRAMMING|C programming|R2C TECHNOLOGIES


 

C Programming Operators


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 the following types of operators − Arithmetic Operators. Relational Operators. Logical Operators.

The following table shows all the arithmetic operators supported by the C language. Assume variable A holds 10 and variable B holds 20, then −

Operator

Description

Example

+

Adds two operands.

A + B = 30

Subtracts second operand from the first.

A − B = -10

*

Multiplies both operands.

A * B = 200

/

Divides numerator by de-numerator.

B / A = 2

%

Modulus Operator and remainder of after an integer division.

B % A = 0

 

Increment and decrement operators 

Increment and decrement operators are unary operators that add or subtract one, to or from their operand, respectively. They are commonly implemented in imperative programming languages. ... The increment operator increases, and the decrement operator decreases, the value of its operand by 1.

The following table shows all the arithmetic operators supported by the C language. Assume variable A holds 10 and variable B holds 20, then

++

Increment operator increases the integer value by one.

A++ = 11

--

Decrement operator decreases the integer value by one.

A-- = 9

 

Assignment Operators

Assignment operators are used to assigning value to a variable. The left side operand of the assignment operator is a variable and right side operand of the assignment operator is a value. This operator is used to assign the value on the right to the variable on the left. 

Operator

Example

Same as

=

a = b

a = b

+=

a += b

a = a+b

-=

a -= b

a = a-b

*=

a *= b

a = a*b

/=

a /= b

a = a/b

%=

a %= b

a = a%b

 

C Relational Operators

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. Relational operators are used in decision making and loops.

Operator

Meaning of Operator

Example

==

Equal to

5 == 3 is evaluated to 0

> 

Greater than

5 > 3 is evaluated to 1

< 

Less than

5 < 3 is evaluated to 0

!=

Not equal to

5 != 3 is evaluated to 1

>=

Greater than or equal to

5 >= 3 is evaluated to 1

<=

Less than or equal to

5 <= 3 is evaluated to 0

Logical operators

 

Operator

Name

Description

&&

Logical and

Returns true if both statements are true

||

Logical or

Returns true if one of the statements is true

!

Logical not

Reverse the result, returns false if the result is true

 

C Programming bitwise operators

Bitwise operators are special operator set provided by 'C. ' They are used in bit level programming. These operators are used to manipulate bits of an integer expression. Logical, shift and complement are three types of bitwise operators.

 

Operators

Meaning of operators

&

Bitwise AND

|

Bitwise OR

^

Bitwise exclusive OR

~

Bitwise complement

<< 

Shift left

>> 

Shift right

 

Other Operators

 Comma as an operator
The comma operator (represented by the token) is a binary operator that evaluates its first operand and discards the result, it then evaluates the second operand and returns this value (and type). The comma operator has the lowest precedence of any C operator, and acts as a sequence point. 

The sizeof operator

Sizeof is a much used operator in the C or C++. It is a compile time unary operator which can be used to compute the size of its operand. The result of sizeof is of unsigned integral type which is usually denoted by size_t. sizeof can be applied to any data-type, including primitive types such as integer and floating-point types, pointer types, or compound datatypes such as Structure, union etc.

 

Other operators such as ternary operator ?:, reference operator &, dereference operator * and member selection operator -> will be discussed in later tutorials.

 

USD TO INR C++ PROGRAMMING

  NALLAMUTHU GOUNDER MAHALINGAM COLLEGE                                                 POLLACHI-642001                                     ...