Operators In C Language

Operators in C

  • Arithmetic operators

  • Cast operator

  • Increment and Decrement

  • Bitwise operators

  • Comparison operators

  • Assignment operators

  • sizeof operator

  • Conditional expression operator

Arithmetic Operators

C supports the arithmetic operators        :

+             Addition
-              Subtraction
*             Multiplication
/              Division
%            Modulo (remainder)

The Cast Operator

The cast operator temporarily changes the type of a variable
if either operand is a double,

1
2
3
4
5
6
7
8
9
10
11
intmain(void)
{
  inti=s,j=4;
  doublef;
   
  f=(double)i/j;
  f=i/(double)j;
  f=(doub1e)i/(doub1e)j;
  f=(doub1e)-(i/j);
  return0;
}

 

Increment and Decrement Operator

c has two special operators for adding and subtracting one from a variable

++  iincrement
--    decrement

These may be either prefix (before the variable) or postfix (after the variable):

Example :

int i =5, j = 4;

i++;                        /*“i’ becomes 6 */

j++;                        /*“j”becomes3 */

--i;                          /*”1” becomes 7 */

Prefix and Postfix

  • The prefix and postfix versions are different
1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>
intmain(void)
{
  inti,j=5;
  i=++j;
  printf(“i=%d,j=%d\n,i,j);
  j=5;
  i=j++;
  printf(“i=%d,j=%d\n,i,j);
  return0;
}

here first is equivalent to :

  • j++;
  • i=j;

second is equivalent to :

  • i=j;
  • j++;

Result is like

i=6 and j=6;

i=5 and j=6;

Comparison Operators

  •  C supports the comparison operators:
    <             less than
    <=           less than or equal to
    >             greater than
    >=           greater than or equal to
    ==           is equal to
    !=            is not equal to
  • These all give 1 (non zero value, i.e. true) when the comparison succeeds and 0 (i.e. false) when the comparison fails

Logical Operators

  • C supports the logical operators:


&&         and
||           or
!             not

  • These also give I (non zero value, i.e. true) when the condition succeeds and 0 (i.e. false) when the condition fails
1
2
inti,j=10,k=29;
i=((j>5)&&(k<100))||(k>24);

Bitwise Operators


C has the following bit operators which may only be applied to integer types:

&             bitwise  and
|              bitwise inclusive or
^             bitwise exclusive or
~             one’s compliment
>>           right shift
<<           left shift

 

Assignment


Assignment is more flexible than might first appear
An assigned value is always made available for subsequent use

1
2
3
int i, j, k, l, m, n;
i = j = k = l = m = n;
printf("%i\n, j = 93");

 

“n= 22” happens first, this makes 22 available for assignment to “m”. Assigning 22 to “m” makes 22 available for assignment to “I” etc.

“j” is assigned 93, the 93 is then made available to printf for printing.

 

Other Assignment Operators


There is a family of assignment operators:

+=           -=            *=           /=           %=

&=          |=           ^=

<<=        >>=


In each of these:
expression1 op= expression2

 
is equivalent to:
(expression1) = (expression1) op (expression2 )

1
2
3
4
5
6
7
8
9
a += 27;
a = a + 27;
 
f /= 9.2;
f = f / 9.2;
 
i *= (j + 2);
i = i * (j + 2); 
is equivalent to: 

 

 

Research and Development

With a focus on R&D, Micromagine embedded software engineers go far and wide exploring the breadth of capabilities and fields of application for the next generation of industry hallmarks, identifying the potential pockets of growth for our customers.
Some of the latest examples of our R&D include studying and testing Android OS porting to custom hardware platforms and trying new dimension technologies such as motion controller in game development.

Embedded System Expertise

  • Deep experience across multiple embedded platforms (ARM Cortex M series, ARM64/aarch64, Intel x86-64)

  • Custom device driver design and implementation (Linux or microcontroller or otherwise)

  • Video- and audio-rate (or higher), low-latency DSP algorithms

  • Multi-threaded applications and data processing

  • Rapid prototyping

Quality Assurance

Quality Assurance of embedded systems is also available as a separate service for our clients. We provide testing and debugging for a range of embedded solutions.
To craft efficient, resilient, and infallible software, we’ve established two focused QA Labs: Firmware & Embedded QA Lab, and Mobile QA Lab, which are applicable during unit, integration, system, and acceptance testing.

 

Powered By by Micromagine Web Solutions