WHAT IS VARIABLE IN C



  VARIABLE IN C 

 # VARIABLE IS A TYPE OF CONTAINER WHICH STORE SOME DATA LIKE  NUMBER ,CHARACTERS ETC


In C, there are different types of variables (defined with different DATATYPE), for example:

  • int - stores integers (whole numbers), without decimals, such as 123 or -123
  • float - stores floating point numbers, with decimals, such as 19.99 or -19.99

  • char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes.                                                                                                                                                                                                                                

Declaring (Creating) Variables


Variable stores in different types of datatype .It shows what types of data you stores in Variable .  

type variableName = value;      

. type contain which type of data you store Ex.  int , float , char etc.     
. variable name refers what a unique name of container Ex.Add,SUM etc.
. value store what value input in a container.  


Example

Create a variable called myNum of type int and assign the value 15 to it:

int myNum = 15;    
                                               

  Types of Variable

1.  Local variable     
2.  Global variable
3.  Static variable  
4.  Auto variable
5.  Extern variable

1.LOCAL VARIABLE  :-  A local variable is a type of variable that we declare inside a block or a function, unlike the global variable. Thus, we also have to declare a local variable in c at the beginning of a given block. A user also has to initialize this local variable in a code before we use it in the program.

2. GLOBAL VARIABLE :- The variables that are declared outside the given function are known as global variables. These do not stay limited to a specific function- which means that one can use any given function to not only access but also modify the global variables.     
3. STATIC VARIABLE :- Static variables are initialized only once. The compiler persists with the variable till the end of the program. Static variables can be defined inside or outside the function. They are local to the block. The default value of static variables is zero. The static variables are alive till the execution of the program. 

4. AUTO VARIABLE :-  All the Local  variable is automatic variable by default .They are also known as auto variable .


Syntax:

auto data_type variable_name;
or
data_type variable_name; (in local scope)

5. EXTERN VARIABLE :-  External variables in C can be shared between multiple C files. We can declare an external variable using the extern keyword.

Their scope is global and they exist between multiple C files.

Syntax:

extern data_type variable_name;













Previous Post Next Post

Contact Form