Anda di halaman 1dari 4

Logical operators:- C supports three logical operators

Operator meaning
&& Logical And
|| Logical or
! Logical not
Eg:- ( A > 55) && ( B = = 5)
The above expression is true if both the conditions (a>5) and ( B == 5) are true other wise the
expression is false.
( a > 55) || ( b = = )
The above expression is true if any one of the above conditions is true.
The expression which combines two or more relational expressions is called as logical expression
or a compound relational expression. The truth table of logical expression is

Condition1 Condition 2 C1 && C2 C1 || C2


F F F F
F T F T
T F F T
T T T T

Assignment Operator: - It is used to assign the result of an expression present on the left side to the
variable present at the right side of the expression. The assignment operator is “ =”.
Ex:- a = b * c;
In the above example the expression b * c is evaluated and the result will be assigned to a. c supports
short hand assignment operators. Syntax is as follows
Variable operator = Expression

Simple assignment operator short hand assignment operator


a = a +1 a+=1
a=a*b a*=b
b=b%2 b%=2

Increment / decrement Operator: - The increment / decrement operators are very useful in c
language. They are widely used in looping controls. These operators are used with one operand. Hence
these are also called unary operators. Hence these operators can be used before or after an operand. The
operators are ++ and - -. The operator ++ adds 1 to the operand where as - - will decrement 1 from the
operand.
Syn: - Operator variable
Ex:- ++ a pre increment
a ++ post increment
a-- post decrement
--a pre decrement
If the operator is used before the operand then it is called prefix operator. Here first the value will
be incremented or decremented and then the value will be displayed.
If the operator is used after the operand then it is called postfix operator. Here first the value will
be displayed then incremented or decremented.

Conditional Operator: - It is also called ternary operator. The pair ( ? : ) is called as conditional
operator.
Syn: - Expression1 ? expression2 : expression3
In the above syntax first the expression1 is evaluated basing on the result expression2 or expression3
will be executed. If exp1 is true the exp2 is executed or exp3 is executed.
Ex:- (a>b) ? a: b

Bitwise operators: - C supports a rich set of bit manipulation operators. These operators allow the
programmer to access and manipulate individual bits with in a data. These operators are used for testing,
complimenting or shifting bits. The bit wise operators are
Operator meaning
& Bitwise And
| Bitwise or
^ Bitwise xor
>> Bitwise right shift
<< Bitwise left shift
~ Bitwise compliment

Bitwise and: - The operator is represented as ‘&’. The bitwise and operator operates on pair of bits to
yield a resultant bit. The truth table of Bitwise and is
a b a&b
0 0 0
0 1 0
1 0 0
1 1 1
For example a =3, b =17 , c are three integers variables.
C=a&b
Binary equivalent of a is 0000 0000 0000 0011
Binary equivalent of b is 0000 0000 0001 0001

Result c is 0000 0000 0000 0001

The value of c is 1

Bitwise Or: - the operator is represented as ‘|’. The bitwise or operator operates on pair of bits to yield a
resultant bit. The truth table of Bitwise or is

a b a|b
0 0 0
0 1 1
1 0 1
1 1 1

For example a =12, b =17 , c are three integers variables.


C=a|b

Binary equivalent of a is 0000 0000 0000 1110


Binary equivalent of b is 0000 0000 0001 0001

Result c is 0000 0000 0001 1111

The value of c is 47

Bitwise xor: - The operator is represented by a symbol ^. It is also called as exclusive R operator. The
rules that give the value of the resulting bit obtained after xor of two bits is shown in truth table.
a b a^b
0 0 0
0 1 1
1 0 1
1 1 0

Xor returns one only if one of two bits are 1, it returns zero only if the two bits are identical

For example a =22, b =14 , c are three integers variables.


C=a^b

Binary equivalent of a is 0000 0000 0001 0110


Binary equivalent of b is 0000 0000 0000 1110

Result c is 0000 0000 0001 1000

The value of c is 24

Left shift operator: - This operator is represented by a symbol <<. It operates on a single variable. It
shifts each bit in the operator to the left. The no of places the bits are shifted depends on the number
following operands

Eg:- let int a=10, b ;

Binary equivalent of ‘a’ us 0000 0000 0000 1010 then a<<3

We shift all bits in 3 places to the left as the bits are shifted to left. Blanks are created on the right. These
blanks are always filled with zero. Therefore

B = a << 3 gives 0000 0000 0101 0000

Right shift operator: - This operator is represented by a symbol >>. It operates on a single variable. It
shifts each bit in the operator to the right. The no of places the bits are shifted depends on the number
following operands

Eg:- let int a=10, b ;

Binary equivalent of ‘a’ us 0000 0000 0000 1010 then a>>3

We shift all bits in 3 places to the right as the bits are shifted to right. Blanks are created on the left. These
blanks are always filled with zero. Therefore

B = a >> 3 gives 0000 0000 0000 0001

Once compliment operator: - it is represented with tilde symbol ( ~ ). It operates on single variable. On
taking once compliment of a number all once present in the number are changed to zeros and all zeros are
changed to once.

Eg:- Let int a=15, b; b = ~ a;

Binary equivalent of a is = 0000 0000 0000 1111


~a= 1111 1111 1111 0000

So the resultant value is negative if left most priority bit is 1.

Size of operator: - The size of operator used to display the number of bytes occupied by an operand.
The operand occupies the operand may be a variable, a constant, or a data type.

Eg: - int a; size of(a) will display 2.

Comma operator: - The comma operator is used to separate the variables.

Expression
An expression is combination of operand and operators. It is the combination of 2 or more
operands and with an operator or many operators. A operand may be a variable or constant or a function.
In other words expression is a formula. Expressions are classified into 3 types
1. Arithmetic Expression
2. Relational Expression
3. Logical Expression

Explain I/o functions:


I/o statements are used to read and write data in c programming. These are embedded in stdio.h file. There
are two types of I/O functions. They are
1. Formatted function 2. Unformatted function

1. Format function:- output function is printf() and input function is scanf()

2. Unformat function:- input functions getchar(), gets(), getch(), getche()


Output functions putchar(), puts()

getchar(): - This function is input function. It is used for reading a single character from the keyboard.
Syn:- v = getchar(); where v is a character variable.

gets(): - This function is a input function. It is used to read a string from the keyboard.

getch(): - This function is also input function. It is used for reading a single character from the keyboard.
Another use of this function is to maintain the output on the screen till you have not press the enter key.

getche(): - This function is also input function. It works similar to getch() function except this function
displays accepted character on the screen.

putchar(): - this function is a output function. It is used to display single character on the screen.

puts(): - This function is a output function. It is used to display string message on the screen.

Symbolic Constant:- it is a name substituted for a variable. Its value cannot be changed during the
execution of program. Symbolic constants are also called ‘c’ preprocessor symbolic constant or compiler
directories. These are called compiler directories because this constants gives direction to the compiler for
assigning a constant to a variable.
Syn: - # define symbolicname constant
Eeg: - # define Pi 3.142 # define name “raju”

Anda mungkin juga menyukai