Skip to main content

C Variable and Datatype



Variables And Datatypes In C Language

Variables


Variables is use to carry the value.and it can be reused many times in a program. variables used to specify the particular  memory location. Variable name is user defined name variable defined once will remain same . During program execution value of variable can be changed by using operators.



1.Rules /Naming of a Variable


  • They must begin with a letter. It can't start with a digit.
  • Keyword and reserved are not allowed as variable name.
  • White space are not allowed in variable name.
  • Name of variable maximum length of 31 character.more than 31 character length are invalid.
  • Uppercase & lowercase letter are different in c, so variable defined with upper letter are different from lower case letter variables.   
  • Special characters like #, $ are not allowed.
  • Variable names are case sensitive.
 2.Syntax/ Define a Variable

datatype variable-name;

3.Declaration of a Variable


int x;

char y;
float z;

4.Initialization of Variable

 int x=10;
char a='xyz';
float f=34.12;

5.Types of Variable in C







1.Local Variable: A variable that defined within a the function is called local variable. 
Example:
void add()
{
int a=20;//local variable
}

2.Global Variable: A Variable that defined outside the function is called global variable.

Example:
int a=20;//global variable 
void add()
{
int b=10;//local variable
}

3.Static Variable: Static variable can be defined inside or outside the function. A variable declared with a static keyword is called static variable. 

Example:
void add()
{
int a=10;//local variable
static int b=20;//static variable
a=a+1;
b=b+1;
printf("%d,%d",a,b);
}

4.External variable: A variable declared outside the function is called external variable. A variable is declared with extern keyword
is called external variable.
Example:
extern int a=20;//global variable 
void add()
{
int b=10;//local variable
}

5.Automatic variable:A variable declared within the function is called automatic variable. A variable is declared with auto keyword is called automatic variable.

Example:
void add(){
int a=10;//local variable(also automatic)
auto int b=20;//automatic variable
}

Datatypes in C language
Datatype defines the type of the variable here type of the variable means its may be integer,float,character,boolean etc.
According the datatype program assign memory to the variable for example if a datatype is a integer of a variable then 4 bit memory assign to that variable.

C datatype are used to

  • Identify the type of the variable when it is declared.
  • Identify the type of the return value of a function.
  • Identify the type of parameter expected by a function.                                                                                                                                  
Primitive Data Type

The size and range of int,short,long are compiler dependent.


Derived datatype and user-defined explain in up next Tutorial. 
              NEXT TOPIC AVAILABLE SOON AS...... 



Comments

Post a Comment

Popular posts from this blog

Let's Be Technical

.   Programming Languages And There       Importance       Before you know about programming  language  we  must  know about languages. the language is a communication medium why which we can understand other person the language way of the transformation of various ideas and thoughts among people. After this  now we  know about programming language a programming language is a formal language, which comprises a set of instructions that produce various kinds of output. Programming languages are used in computer programming to implement algorithms. Most programming languages consist of instructions for computers. How its Importance of Programming Language Important in your daily life we use various device & tools that are works one the programming language like microwave ,ATM, Lift etc.  Programming language is important  because it define semantics and grammar which allow the pro...

Rapid View Of Technology

  Currently Running Top 10 Programming Languages C programming language                         C language is the most popular and and widely used programming language.The C language is developed in 1972 by  Dennis Ritchie at bell laboratories of AT&T American Telephone & Telegraph, located in the U.S.A . C language is also knows as mother and structured programming language.C language is a basic language of all other languages. C++ programming language                                 C++ is object oriented programming language. C++ programming language was developed in 1980 by Bjarne Stroustrup  at bell laboratories of AT&T,located in U.S.A  . C++ is totally based on oops concept. HTML                              ...

C Looping Statements

Looping/Iterative Statements What is Loop one statements are executed one or more time .looping simplify the complex problems into the easy one.loop provides code reusability.  we do not need to write same code again and again.looping is used to traverse the element of  data structure. Types of loops 💥 For Loop:- In C the For loop is used to iterate a part of the program many time.In the for loop number of iteration is fixed. Syntax:- for(initialization,condition,increment/decrement) { statement }                                   Flow chart of for loop Example                                                                      #include<stdio.h>    #include<conio.h>...