Computer Science, asked by sunil523777, 4 months ago

explain In detail about the operaters in C language with examples​

Answers

Answered by kalivyasapalepu99
2

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 OperatorsRelational OperatorsLogical OperatorsBitwise OperatorsAssignment OperatorsMisc Operators

An operator is a symbol that operates on a value or a variable. For example: + is an operator to perform addition.

C has a wide range of operators to perform various operations.

C Arithmetic Operators

An arithmetic operator performs mathematical operations such as addition, subtraction, multiplication, division etc on numerical values (constants and variables).

OperatorMeaning of Operator+addition or unary plus-subtraction or unary minus*multiplication/division%remainder after division (modulo division)

Example 1: Arithmetic Operators// Working of arithmetic operators #include <stdio.h> int main() { int a = 9,b = 4, c; c = a+b; printf("a+b = %d \n",c); c = a-b; printf("a-b = %d \n",c); c = a*b; printf("a*b = %d \n",c); c = a/b; printf("a/b = %d \n",c); c = a%b; printf("Remainder when a divided by b = %d \n",c); return 0; }

Output

a+b = 13 a-b = 5 a*b = 36 a/b = 2 Remainder when a divided by b=1

The operators +, - and * computes addition, subtraction, and multiplication respectively as you might have expected.

In normal calculation, 9/4 = 2.25. However, the output is 2 in the program.

It is because both the variables a and b are integers. Hence, the output is also an integer. The compiler neglects the term after the decimal point and shows answer 2 instead of 2.25.

The modulo operator % computes the remainder. When a=9 is divided by b=4, the remainder is 1. The % operator can only be used with integers.

Suppose a = 5.0, b = 2.0, c = 5 and d = 2. Then in C programming,

// Either one of the operands is a floating-point number a/b = 2.5 a/d = 2.5 c/b = 2.5 // Both operands are integers c/d = 2

Similar questions