0% found this document useful (0 votes)
39 views

C Operators PDF

The document discusses keywords, variables, data types, operators, and conditional statements in C programming. It provides examples of variable declaration and usage, arithmetic, assignment, increment/decrement, relational, logical, and bitwise operators. It also covers the ternary operator.

Uploaded by

Gourav Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

C Operators PDF

The document discusses keywords, variables, data types, operators, and conditional statements in C programming. It provides examples of variable declaration and usage, arithmetic, assignment, increment/decrement, relational, logical, and bitwise operators. It also covers the ternary operator.

Uploaded by

Gourav Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

C Programming Language

-----------------------

Keywords: special words which already present in c library.

40 keywords

eg:

int

float

for

break

if

else

2) variable :

data type

int x=10, b2=20;

1) 31 character length

2) int rollno;

int roll_no;

int roll no; // error

3) case-senstive

int rollno;
Rollno = 20; // error

rollno = 20; // true

4) int x1,x2,x3;

int 1x, 34x;

start with letter

3) Operators:

1) Arithmetic Operator

+ , - , * , / , %(modulus)

2) Assignment Operator

=, +=, -=, *=, /=, %=

3) Increment or decrement

(++) or (--)

int x=10;

x++; // post inc

x=11;

++x; // pre inc

x=11
4) Relational Operator

>, <, >=, <=, ==, !=

x=13, y=5

x > y - true

x!=y

x=10 , y=10

x == y true

x=y

5) Logical Operator

&& - AND

|| - OR

! - Not

true = 1

false means 0

x=15, y=5, z=9

x>y && x>z


AND -

A | B | Output(A&&B)

-----------------------

0 0 0

0 1 0

1 0 0

1 1 1

x=10, y=4, z=14

( x>y || x<z )

OR

A | B | Output(A||B)

-----------------------

0 0 0

0 1 1

1 0 1

1 1 1

NOT

0 --> 1

1 --> 0

6) Bitwise Operator

& - Bitwise AND Operator

| - " Or

^ - " XOR
<< - " left shift

>> - " right shift

~ - negation

int b1 = 4 , b2 = 5, b;

Bitwise AND -

b = b1 & b2;

b1 - 0100 - 4

b2 - 0101 - 5

-----------------------

b= 0100 - 4

Bitwise OR -

b = b1 | b2;

b1 - 0100 - 4

b2 - 0101 - 5

-----------------------

b= 0101 - 5

Bitwise XOR -

b = b1 ^ b2;

b1 - 0100 - 4

b2 - 0101 - 5

-----------------------

b= 0001 - 1
truth table of XOR

A | B | Output(A^B)

-----------------------

0 0 0

0 1 1

1 0 1

1 1 0

Compliment ~ :-

b = ~b1 - ~4

~ 0100

----------------

1011 - 11

-16

- ------

-5 final result

b = ~23

168421

~10111 -

------------

01000 - 8

-32

-----------------

-24
7 ) Conditional Operator or Ternary Operator

(condiation)?expression 1 : expression 2;

cond. true - exp 1

cond. false - exp 2

You might also like