Constants, Operators
Constants, Operators
1
Variable vs Constant
Variable: A variable is nothing but a name given to a storage area.
A variable may take different values at different times during execution.
Variable declaration: data_type variable_name;
data_type variable_name=value;
Constant: fixed value that do not change during the execution of a
program.
Constant declaration: #define constant_name value
Rules for Defining Constant
Naming rule is the same as naming a variable.
#define must be written before defining a constant
After defining the symbolic name should not be assigned any other value in the program
#Define A 15 invalid
#define A 11 valid
Example Code to Define a Constant
#include<stdio.h>
Output?
#define PI 3.142
Take input of radius:
int main(){
float radius, area; 3
printf(“Take input of radius:");
scanf("%f",&radius); Area of circle=28.278000
area =PI*radius*radius;
Area of circle=28.278
printf(“Area of circle=%f\n",area);
printf(“Area of circle=%0.3f\n",area);
}
Operators
Operator: Operator is a symbol that tells the computer to perform certain
mathematical or logical manipulations.
C operators can be classified into a number of categories:
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Increment and decrement operators
Bitwise operators
Special Operators
Arithmetic Operators