2. STRUCTURE OF C PROGRAM
#include <stdio.h>
/* Include files for input/output functions*/
#define const_namevalue
/* constant declaration if required */
main() /* Main function */
{ /* each declarations and statements are separated by semi colon */
declarations
/* variables; arrays; records;
function declarations etc */
statements
}
4. ARITHMETIC OPERATOR
• Arithmetic operators used to perform arithmetic operation.
• There are following arithmetic operators in C language.
OPERATOR DESCRIPTION
+ Adds two operands
- Subtract second operands
from first
* Multiply two operand
/ Divide numerator by
denumerator
% Remainder of division
5. RELATIONAL OPERATOR
• Relational operator compare between two operands and return
in terms of true or false.
• These are following relational operators.
OPERATOR MEANING
> Greater then
< Less then
>= Greater or equal to
<= Less or equal to
= Equal to
!= Not equal to
6. LOGICAL OPERATOR
OPERATOR DESCRIPTION
&& Logical AND
|| Logical OR
! Logical NOT
•A logical operator is used to compare or evaluate logical and
relational expressions.
•These are following logical operator.
7. ASSIGNMENT OPERATOR
OPERATOR DESCRIPTION EXAMPLE
= Assigns value from
right side operands to
left side operand
A=b
+= Adds right operand to
left operand and assign
he result to left
A+=b is same as a=a+b
-= Subtracts right operand
from the left operand
and assign the result to
left operand
A-=b is same as a=a-b
*= Multiply left operand
with the right operand
and assign the result to
left operand
A*=b is same as a=a*b
/= Divides left operand
with the right operand
a/=b is same as a=a/b
9. CONDITIONAL OPERATOR
• It is also known as ternary operator and used to evaluate
conditional expression.
• E.g: expr1? Expr2:expr3
• If expr1 condition is true? Then value expr2 otherwise value
expr3
10. BITWISE OPERATOR
• Bitwise operator perform manipulations of data at bit
level.
• These operator also perform shifting of bits from right to
left .
• Bitwise operator are not applied to float or double.
OPERATOR DESCRIPTION
& Bitwise AND
| Bitwise OR
<< Left shift
>> Right shift
13. Arithmetic Expression
• An expression is a combination of variables,
constants and operators written according to the
syntax of C language.
•x = x + 2 x += 2
•i = i +1 i++ or ++I
// the value of x is added with the value of i
14. EXAMPLE
x + y * z / 2 + p x + y -z / 2 * p
x + (y * z)/ 2 + p (x + y)-z / 2 * p
x + ((y * z) / 2)+ p (x + y) –(z / 2)* p
(x + ((y * z) / 2))+ p (x + y) –((z / 2) * p)
((x + ((y * z) / 2)) + p) ((x + y) –((z / 2) * p))
15. Conditional Expression
•An expression expis evaluated and
–if the value is nonzero (or true orepresented by 1) then
expression exp1is the final value
–otherwise exp2is the final value of entire expression.
exp ? exp1 : exp2