Wednesday, 7 January 2015

Variable in C Programming

Variable in C Programming

Variable in C programming language is a container that store the data.Variable  has two part. One part is data type and another part is name of the variable.That mean each variable has a type and a  name.

For example :




int banana;    

[ In this statement of c there is a variable declaration. Here “int” is data type and  “banana” is the name of variable]









You may have question now what is data type?
A data type represents a type I mean classification of the data which you can process using your computer program. It can be numeric,alphanumeric,decimal etc


Now I am going to introduce you general built in data type table in c language with explanation

Type
Description
Value
Char
Character type data use single quotation around characters
'a', 'l', 'm', 'F' etc.
int
Natural number integer type
….-1,100,2,19…… etc
float
Numeric type that has either fractional form or exponent form
-5.0
0.000234
-0.42E-5
double
Implies, a double has 2x the precision of float
15436059087.21
void
It represents the absence of type



Variable Type in C programming:

There are two type of variable in c programming language
     1) local variable
     2) global variable

What does mean global variable in c:

Global variables are defined outside of a function,usually on top of the program. The global variables will hold their value throughout the life time  of your program. They can be accessed by any function.That mean a global variable is available for use througout your entire program after its declaration.

What does mean local variable in C:


Local variable is a variable have a local scope.Local variable is accessible only from function or block in which it is declared.
Variable declaration in c:


int main()
{
int IntegerVariable;
int CharacterVariable;
return 0;
}

It is possible to declare more than one variable at the same time?
Answer :Yes like below


int main()
{
int variable1, variable2, varibale3;
int abc, def, mmm;
return 0;

}

It is possible to declare a variable and assign a value  at the same time?
Answer:Yes like below

int main()
{
int ivar;
                int ivar = 10;
return 0;
}

Const Type Variable declaration

      int main()
{
const float PI = 3.14;
char = 'A';
return 0;
}
int main()
 {
  const float PI = 3.14;
  char = 'A';
  return 0;
 }







No comments:

Post a Comment