C Control StatementsC FunctionsC ArrayC PointerC Dynamic MemoryC StringC MathC StructureC UnionC File HandlingC PreprocessorC Command LineC Misc |
Variables in cThe Variable is the name of memory location that can used to stored values. it can take different values but take one value at a time.so these all values can change during execution of program. The datatype is associated with every variable and datatype decides what values the variables can accept or take. there are rules for naming variables are same as that for naming identifiers. Declaration of variablesSO it is declare variable before it is used in the program. declaration of variable specifies its name and datatype.the talk about type and range of values that variables can stored its depend on data type. Syntax of declaration of variables is
Here in the Declaration data type may int,float,char, double etc. its depend on your choice how value you want to store. some examples of declaration of variables are-
In this example x is variable of type int,salary variable is of type float, and grade variable is of type char. The datatype short int can written as int and long int can written as long.we can declare more then one variable in one statement example
Initialization of variablesWhen a variable is declare it contain garbage value. if we want some value we can assign some initial value to the variable during the declaration. this is known initialization of variable. example-
Rules for Declaration of variables
1. The variable name should consist of only uppercase and lowercase letters,digits and underscore sign(_). Types of variablesThere are five types of variables in c programming
1. Local variable Local variablesThe variables in c programming that are declare inside function or inside block is known as local variables
global variablesvariables in c programming that are declared outside of all function or outside of block is known as global variables. Any function can use and change the value of global variables. it is available to all functions. And the global variable automatic initialize by zero
Static variablesThe static variable are declare by writing static keyword in front of the declaration. if a static variable is not initialize then it is automatically initialize to zero. And the static variable only initialize once
When we call function every time the value is int count1 same everytime example 11111111 so on. but static variable count2 variable print different increment every time by one example 123456789 so on Automatic variablesAll variables in c programming are declare insides in block is known Automatic variables or local variables. we can explicitly declare Automatic variable using Auto keyword
External variablesThe variables in c programming that have to used by many functions and in a different programs and files can declare as external variables. The default initial value of uninitialized external variable is Zerothe keyword extern is not specified in definition but some compiler may allow the extern keyword. So its better to avoid the extern keyword in the definition Userdefined.h
|