Variable
A quantity whose value may change during execution of the program is called variable. A variable represents a location in the computer's memory.it is used to store program's input data and its result during program execution. The name of the memory location .i.e. the variable name remains fixed during program execution. however data stored in variable may change during program execution.Declaration of Variables
Specifying the variable names and their data types in the program is called declaration of variables. C is a typed language. It means that all variables must be declared before they are used in the program. The C-compiler will give an error if an undeclared variable is used in a program.Variable Initialization
In C program, when a variable is declared, the compiler allocates some memory space for it. A meaningless data may be assigned to it. This meaningless data is called garbage data. A value can also be assigned to a variable at the time of its declaration. Assigning a value to a variable at the time of its declaration is called variable initialization.Write a program to declare and initialize two variables of 'int' type. Calculate the sum and average of these values and display the result on screen.
C |
C++ |
# include < stdio.h
>
# include < conio.h >
void main ( )
{
int x , y ;
float sum , avg ;
x = 25 , y = 5 ;
sum = 25 + 5 ;
avg = sum / 2.0 ;
printf ( " Sum is = %f \n "
, sum ) ;
printf ( " Average is = %f " , avg
) ;
}
|
# include <
iostream >
int main ( )
{
int x , y ;
float sum , avg ;
x = 25 , y = 5 ;
sum = 25 + 5 ;
avg = sum / 2.0 ;
cout << “ Sum is : “ << sum ;
court << “ Average is : “
<< avg ;
return
0;
}
|
Constants
The quantity whose the value cannot be changed during the execution of a program is called constants. In C language, an identifier. A value is assigned to it at the time of its declaration. Similarly, the 'define' directive can also be used to define constants identifier. Once a value is assigned to a constant identifier, it cannot be changed during program execution.Types of Constants
C-language provides following types of constants:- Numeric constants
- Character constants
- String constants
1. Numeric Constants
Numeric constants consist of numbers (or numeric value). These may be positive or negative values. The numeric constants are further divided into two types:- Integer constants
- Floating-point constants
No comments:
Post a Comment
Thanks For Visiting Here...!! I will Reply you as soon as possible.