Lesson 3 C Operators
Lesson 3 C Operators
When a programmer wants to perform some type of mathematical operation then you
have to use operators.
Bitwise Operator in C.
1. Arithmetic Operators in C
1|P ag e
Lesson 3
2|P ag e
Lesson 3
2. Increment Operator in C
Mainly used for incrementing the value of an integer. It is represented by the ‘++’
operator. ++x will increase the value of the variable x instantly. But if it is placed after
the variable then it gets increased before the execution of the next statement.
3. Decrement Operator in C
Mainly used for decrementing the value of an integer. It is represented by the ‘–’
operator. –x will decrease the value of the variable x instantly. But if it is placed after the
variable then it gets decreased before the execution of the next statement.
4. Assignment Operators in C
The purpose of this operator is to assign value to a variable. The most used assignment
operator is “=”.
3|P ag e
Lesson 3
Write a C program that accepts principle, rate of interest, time and compute the
simple interest.
4|P ag e
Lesson 3
6. Logical Operators in C
In the C programming language, Logical operators are mostly used for decision
making. A logical operator returns either 0 or 1 whether the condition is true or false.
7. Conditional Operator in C
Also known as Ternary operator. The main purpose of conditional operators is in
decision making statements. It is similar to an if-else statement.
5|P ag e
Lesson 3
Operator Precedence in C
In between operators, some have higher precedence and some have lower precedence.
For example, Division has a higher precedence than subtraction operator.
6|P ag e
Lesson 3
Operators which have higher precedence are at the top of the table. And operators
which have lower precedence are at the bottom.
Variables in C language
a Variable is the name of the place in the memory in which we store the data or
information.
Unlike constant, values stored in variables can be changed, we can change the
value of a variables during the execution of a program.
7|P ag e
Lesson 3
5 types of variables in C
i. Local variables
ii. Global variables
iii. Static variables
iv. Automatic variables
v. External variables
Variable Declaration in C
Syntax type variable name;
A variable name can consist of Capital letters A-Z, lowercase letters a-z, digits 0-9, and
the underscore character.
The first character must be a letter or underscore.
Blank spaces cannot be used in variable names.
Special characters like #, $ are not allowed.
C keywords cannot be used as variable names.
Variable names are case sensitive.
Values of the variables can be numeric or alphabetic.
Variable type can be char, int, float, double, or void.
8|P ag e
Lesson 3
Local variables in c
When we declare a variable inside a function or block, then it is called a Local
Variable.
We can use this variable in that block or function in which that variable is
declared.
The lifetime of a local variable is only equal to the lifetime of the function or
block in which it is declared, as soon as that function or block is destroyed, the
local variable is also destroyed and the space it has got in the memory is also
released.
output
When we declare a variable inside a function, then its scope is limited to that variable
so that if we want, we can create a variable with the same name in two different
functions, this will not cause any problem in the program because the scope of both
will be limited to that function.
The memory that the local variable gets is available only till the function in which that
local variable is declared is run in the computer. As soon as the function ends, the
variable’s memory is released and that memory can be used by any other variable of
the program.
9|P ag e
Lesson 3
Global variables in C
Global variables are declared outside the function or block. Generally, the Global
Variable is declared at the top of the program.
The lifetime of a global variable is equal to the lifetime of the entire program, and as
soon as the program ends, the global variable is also destroyed and its available space
in the memory is also released.
Output -:
constant in C
constant defines a variable whose value cannot be changed.
You can use the const Keyword.
Const double PI = 3.14;
10 | P a g e
Lesson 3
# include <stdio.h>
#define PI 3.1415
Int main ()
Area= P1 * radius*radius;
return 0;
11 | P a g e