C programming language, Uncategorized

Operators in C – tccicomputercoaching.com

What is operator?

Operator means simple symbol which is used between operands (variable) during
mathematical process.

Operators-in-C_simple

There are following categories:

1. arithmetic: + – * / %

i.e.

a=6

b=2

printf(“a+b =%d”, a+b);

printf(“a-b =%d”, a-b);

printf(“a/b =%d”, a/b);

printf(“a*b =%d”, a*b);

printf(“a%b =%d”, a%b);

op:

a+b =8

a-b =4

a/b =3

a*b =12

a%b =0

Modulor Operator – % is used in Coding like ro find Number is even or Odd.

if(a%2==0)

{

printf(“a is even”);

}

else

{

printf(“a is odd”);

}

2. relational operator : > >= < <= == !=

For example,

a=6

b=2;

if(a==b)

{

printf(“a and b are same”);

}

else

{

printf(“a and b are not same”);

}

3. logical operator : && || !

&& ||

—————————————————————————————————————–

c.1 c.2 Result c.1 c.2 Result

—————————————————————————————————————–

1. T T T T T T

2. F T F F T t

3. T F F T F t

4. F F F F F F

4. Assignment Operator: =

This operator assign value of right side variable to the left side
variable.

i.e int x=10,y=20 ;

printf(“%d”,x);

x=y;

printf(“%d”,x);

op:

10 20

5. Increment and decrement: ++ – –

Increment ++ and decrement — to change the value of an operand (constant or variable) by 1. Increment ++ increases the value by 1 whereas decrement — decreases the value by 1. These two operators are unary operators, meaning they only operate on a single operand.

i.e,

int x=6;

x++;

printf(“%d”,x);

x- -;

printf(“%d”,x);

op: 7 6

6. Conditional operator:

Syntax: exp1? exp2:exp3

I.E. int x=10,y=20 ,max;

max=x>y?x:y;

printf(“%d” ,max);

OP: 20

7. Shorthand Assignment Operator: += +* +/ +%

i.e

int x=6;

x+=5;

This statement expnad like x=x+5;

x= 6+5;

x=11;

8. Bitwise Operators
: & | > <

The Bitwise operators is used to perform bit-level operations on the operands. The operators are first converted to bit-level and then the calculation is performed on the operands. The mathematical operations such as addition, subtraction, multiplication etc. can be performed at bit-level for faster processing. For example, the bitwise AND
represented as & operator in takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1.

i.e

Assume variable ‘A’ holds 60 and variable ‘B’ holds 13, then –

(A & B) = 12, i.e., 0000 1100

For more information about C programming at TCCI

Call us @ 9825618292

Visit us @ http://tccicomputercoaching.com/

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s