Skip to main content
Home
Live to Learn!

Main navigation

  • Home
  • Learn
    • FoxPro
    • MS-DOS
    • C PRG
    • Java
    • ASP
    • Ruby on Rails
    • ASP.NET
    • E-Books
    • Exam Preparation
    • Tools
  • Blog
  • Forums
  • Contact
User account menu
  • Log in

Breadcrumb

  1. Home
  2. C Programming

Operators in C Programming

Book navigation

  • C Programming Introduction
  • C – Program Code – Basics Part I
  • C – Program Code – Basics Part II
  • Operators in C Programming
  • C – Program Code – Basics Part III
  • C Program Code Basics - Part IV
  • Addition , Subtraction and Multiplication of Matrices
  • Solving Quadratic Equation
  • Sum of sin series
  • Sum of cos series
  • Sum of e series
  • Ascending and Descending order
  • Sorting in Alphabetical Order
  • Factorial of a number
  • Fibonacci Series
  • String Counting
  • String Manipulation
  • Bisection Method
  • Newton Raphson Method
  • Lagrange's Interpolation
By Karthikeyan , 12 May, 2013

Types of Operators in C Programming

Arithmetic Operators

(five)

+ - Addition / unary plus

- - Subraction / unary minus

* - Mulitplication

/ - Division

% - Modulo division

  • % - can’t be used with floating point data
  • C does not have operator for exponentiation
  • In modulo divison, the sign of the result is always the sign of the first operand

e.g.

 -14%3 = -2

14%-3 = 2

Relational Operators

(six)

<  is less than (is complement of >=)

<=  is less than or equal to

>  is greater than (is complement of <=)

>= is greater than or equal to

== is equal to (is complement of !=)

!= is not equal to

Logical Operators

&& - AND

|| - OR

! – NOT

Combines two or more relational expressions, is termed as a logical expression

Assignment Operators

var = var op (exp)

è var op= var

(var – variable, op – operator, exp – expression)

e.g.

 

Simple Assignment Operators

Equivalent Shorthand assignment operators

a = a +1

a +=1

a = a – 1

a -= 1

a = a*(n+1)

a *= n + 1

a = a /(n+1)

A /= n + 1

a = a % b

A %= b

 

Increment and Decrement Operators

++ (Increment)

-- (Decrement)

  • Unary operators
  • Postfix : expression evaluated first, then the value of the variable is incremented / decremented by 1.
  • Prefix: the value of the variable is incremented / decremented by 1, then the expression evaluated.

e.g.

++a, a++

--b, b--

Expression

Value after processing

a = 5;

b = ++a;

a = 6

b = 6

a = 5;

b = a++;

a = 6

b = 5

 

Conditional Operator

Ternary operator pair  “?:”

exp1 ? exp2 : exp3

exp1 is evaluated first, if non zero(true), then exp2 is evaluated, exp1 is false, then exp3 is evaluated.

if(a>b)

x = a;

else

x = b; è

x = (a>b) ? a:b;

 

Bitwise Operator

 Used to manipulate the data at bit level.

& - bitwise AND

| - bitwise OR

^ - bitwise exclusive OR
<< - shift left

>> - shift right

  • Bitwise operators may not be applied to float or double

Special Operators

Comma (,) operator, sizeof operator, pointer operators (& and *), member selection operator (.  and ->)

Comma Operator:

  • Can be used to link the related expressions together
  • Comma op has the lowest precedence of all operators

e.g. in for loops
for(n=1, m=10, n<=m; n++, m++)

size of Operator:

  • It is compile time operator and it returns number of bytes the operand occupies.

e.g.

m = sizeof(sum);

n = sizeof(long int);

k = sizeof(255L);

 

Comments

Featured Blog Posts

Convert Currency in Number to Words (Indian Rupees) - MS Excel
Foxpro Tutorial and Programs
Convert Currency in Number to Words in MS Word
Convert Currency in Number to Words (Indian Rupees) - Version 2
Best way to Use Rupee Symbol in Windows – Easy steps
Convert Currency in Number to Words - MS Access
Creating All in One Windows XP DVD with all Important Applications
RSS feed

© 2009-2025 Live to Learn.In

Terms of Use | Privacy Policy