UrbanPro
true

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Operators in C

Venkateswararao S.
18/01/2017 0 0

Operators in C

Operator:    An operator is a symbol that tells the compiler to perform certain mathematical or logical calculations. Operators are used in programs to manipulate data and variables. The data items that operators act upon are called operands.

Arithmetic Operators:     There are five arithmetic operators in C. there are

                             Operator                         Purpose

                +                              addition

  • subtraction

*                               multiplication

/                              division

%                              remainder after integer division

          The operands acted upon by arithmetic operators must represent numeric values. Thus, the operands can be integer quantities, floating – point quantities or characters. The remainder operator (%) requires that both operands be integer and the second operand be nonzero. Similarly, the division operator(/) requires that the second operand be nonzero.

Ex:-   a, b are integer variables whose values are 10,3.

                                      Expression                               Value

                                          a + b                                       13

                                          a – b                                         7

                                          a * b                                        30

                                          a / b                                        3

                                          a % b                                       1

          The value of an expression can be converted to a different data type if desired. To do so, the expression must be preceded by the name of the desired data type, enclosed in parentheses, i.e.,

                   (data type) expression

          This type of construction is known as a cast.

Unary Operators:

          C includes a class of operators that act upon a single operand to produce a new value. Such operators are known as unary operators. The most common unary operator is unary minus, where a numerical constant, variable or expression is preceded by a minus sign.

Ex:-   -743            -0.2             -0X7FFF               -(x + y)

          There are two other commonly used unary operators: The increment operator, ++, and the decrement operator, - -. The increment operator causes its operand to be increased by 1, whereas the decrement operator causes its operand to be decreased by 1. The operand used with each of these operators must be a single variable.

 

Ex:-   The expression ++ i which is equivalent to writing i= i+ 1.

          A prefix operator first add one or subtract one to the operator and then the result assigned to the variable. A postfix operator first assigns the value to the variable and then increment or decrement to the operand.

Ex:-   a=10;

          b=++a;

          The result of the above statement is, the variable ‘a’ is increment by one and result will be assigned to ‘b’. Then ‘b’ will have the value of 11.

          a=10;

          b=a++;

          First the value of ‘a’ will be assigned to ‘b’, after that ‘a’ will be incremented by one. Then ‘b’ will have the value of 10.

          a=10;                                       a=10;

          b=--a;                                       b=a--; c=b++;

          Result  b = 9.                           Result  c = 10.

Relational and logical operators:

          There are four relational operators in C. They are

                             Operator                         Meaning

                                  <                               less than

                                  <=                             less than or equal to

>                               greater than

>=                             greater than or equal to

                          These operators all fall within the same precedence group, which is lower than the arithmetic and unary operators. The associativity of these operators is left to right.

Equality operators:

                             Operator                         Meaning

                                  ==                             equal to

                                  !=                              not equal to

          The equality operators fall into a separate precedence group, beneath the relational operators. These operators also have a left – to – right associativity.

          These six operators are used to form logical expressions, which represent conditions that are either true or false. The resulting expressions will be of type integer, since true is represented by the integer value 1 and false is represented by the value 0.

          In addition to the relational and equality  operators, C contains two logical operators (also called logical connectives). They are

                             Operator                         Meaning

                                  &&                               and

                                  ||                                or

          These operators are referred to as logical and  and logical or, respectively. The logical operators act upon operands that are themselves logical expressions. The result of a logical and operation will be true only if both operands are true, whereas the result of a logical or operation will be true if either operand is true or if both operands are true. In other words, the result of a logical or operation will be false only if both operands are false.

          C also includes the unary operator ! that negates the value of a logical expression; i.e., it causes an expression that is originally true to become false, and vice versa. This operator is referred to as the logical negation (or logical not) operator.

Operator precedence are summarized below, from highest to lowest.

Operator category                              Operators                                 Associativity

Unary operator                        -  ++  --  !  sizeof   (type)                            RàL

Arithmetic multiply, divide

          and remainder                         *   /   %                                           LàR

Arithmetic and subtract                      +   -                                               LàR

Relational operat

0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

Compiler vs Interpreter
Compiler Interpreter Convert all the code into binary format and execute. Convert one statement at a time and execute, then Convert next statement and execute. After conversion, source...


Basics Of C And C++
C++ is powerful, highly flexible, and adaptable programming language that allows software engineers to organise and process information quickly and effectively. But this high-level language is relatively...

C Program to print Block Letter and Small Case Alphabets using C
/* WAP to print Block Letter and Small Case Alpahbets using C*/ //Hint:use ascii code(value) to print #include#include void main(){ int i; clrscr(); //Block Letters Alphabets printf("Block Letters Alphabets\n");...
S

C for Begginers
C is an procedure oriented programming language. For any begginer the word program is new. Program: Set of instructions to be followed by machine or computer. Instruction Examples: Arithmetic instruction...
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more