Sunday, 24 November 2013

Operators in C

An operator is a symbol that instruct  the compiler to perform specific mathematical or logical operation. C language  has following type of operators:
C Programming
C Programming
•  Arithmetic Operators
•  Relational Operators
•  Logical Operators
•  Bitwise Operators
•  Assignment Operators
•   Misc Operators
This post will explain the arithmetic, relational, logical, bitwise, assignment and other operators.

Arithmetic Operators:

The table  below shows all the arithmetic operators supported by C language. Let  suppose the value of A is  10 and variable B is 20 then:
Arithmetic Operators
Arithmetic Operators

Relational Operators:

The table shows all the relational operators supported by C language. Let  suppose the value of A is  10 and variable B is 20, then:
Relational Operators
Relational Operators


 Logical Operators:

Following table shows all the logical operators supported by C language.Let  suppose the value of A is  1 and variable B has value  0, then:
Logical Operators
Logical Operators


Bitwise Operators:

Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ are as follows:
Assume if A = 60; and B = 13; now in binary format they will be as follows:
BitWise Operators
BitWise Operators

A = 0011 1100
B = 0000 1101
-----------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A  = 1100 0011

The Bitwise operators supported by C language are listed in the following table.Let  suppose the value of A is 60 and variable B is 13, then:
BitWise Operators
BitWise Operators

Assignment Operators:

 following are the assignment operators supported by C language:
assignment operators
assignment operators

Misc Operators ↦ sizeof & ternary

following are  few other important operators including sizeof and ? : supported by C Language.
Misc Operators
Misc Operators

Operators Precedence in C:

Operator precedence determines priority of operators in an expression . It also determines how  expression is evaluated. Some of the operators have higher precedence than others; for an instance , the multiplication operator has higher precedence than the addition operator.
For example x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher precedence than +, so it first gets multiplied with 3*2 and then adds into 7.
The operators with the highest precedence is at the top of the table, those with the lowest are at the bottom. In  an expression, higher precedence operators will be evaluated first.
Operators Precedence in C:
Operators Precedence in C:

C - Overview
C - Basic Syntax
C - Data Types
C - Variables
C - Constants
C - Storage Classes
C - Operators
C - Decision Making
C - Loops
C - Functions
C - Scope Rules
C - Arrays
C - Pointers
C - Strings
C - Structures
C - Unions
C - Bit Fields
C - Typedef
C - Input & Output
C - File I/O
C - Preprocessors
C - Header Files
C - Type Casting
C - Error Handling
C - Recursion
C - Variable Arguments
C - Memory Management
C - Command Line Argumen

Related Posts:

  • Pointers in c  A pointer is an address. Instead of  a variable, it is a pointer to a variable which is  stored somewhere in the memory of the program. Let  examine… Read More
  • Constant and Literals in c The constants refer to fixed values that the program may not change during its execution. These values are also called literals. C Programming Constants can be of any of the  data types like an integer … Read More
  • c Basic Syntax The basic structure of C programming is easy and it will be help full to understand other building blocks of the C programming language. C Programming Tokens: A token in c programming is either a keyword,… Read More
  • Loops in C  This is an attempt at explaining the loops in C .It is not complete, just the basics. C Programming Loop is  a construct which execute a set of statements certain number of times… Read More
  • Arrays in c An array is derived data type which can store similar type of data in sequence memory location. Data may be primitive type i.e  int, char, float, double… C Program… Read More

0 comments:

Post a Comment