Your Email

Concept of Variables and constants in C language (module 8)

In this module we will discuss on the concept of variables and constants in C and the life time of it in any C program.

Do you have similar website/ Product?
Show in this page just for $5 (for a month)
Create an Ad

This is the 8th module on learning C with us. Earlier we discussed on the basic introduction and structure of C, preprocessor it's features, intermediate and executable codes. compilation and execution process of a C program. And keywords and identifiers, data types.
In this section we will discuss on our next topic and most important concepts of using variables and constants in C. And there life time and scope in program.
Concept Of Variables in C :-
A quantity that can vary during the execution of a program is known as a variable. To identify a quantity we name the variable. After naming a variable we need to declare it to compiler of what datatype it is.
The format of declaring a variable is 
Data_type var1,var2,.......,varn;
Where datatype could be float, int, char, or any of the datatypes. Var1,var2,....,varn are the names of variable we use. In case of single variables no commas are required.
Eg.  float a,b,c;
        int e,f;
        char dpr ;
Assigning values to variables :-
When we name and declare variables we need to assign value to the variable. In some cases we assign value to the variable directly like a=10; in our program. 
In some cases we need to assign values to variables after the user has given input for that. Eg. We can ask user to enter any number and input it.
Program to take a value from user and store it in any variable :
{ int a;
float b;
Printf("enter any number\n");
b = 190.5;
Printf ("user entered %d",a);
Printf("b's value is %f",b);
Output :-

Concept Of Constants in C :-
A quantity that does not vary during the execution of program is known as constant, C supports two types of constants namely numeric constants and character constants.
Numeric constants :-
1. Example for an integer constant is 786,-127.
2. Long constant is written with a terminal 'l' or 'L' for example 123456789L.
In next module we will discuss on scope of variables in any C program. For more information please be updated with us as we provide all the modules and cover all the topics regarding #C. Only on Www.newsandstory.com 

module 8
Dalpat I
Content writer