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

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                              ...

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...

C Language Tutorial

C Programming Language Tutorial        What is C Programming                              C Language is most popular and widely used programming language. C language is basic language of all other programming languages so also knows as mother language. that directly interact with the hardware devices like kernel and drivers. C is a Procedural language because solve the programming problem in step by step.  C language  break the program into function. C is a Structured language because break a program into several parts and blocks so that easy to understand this program.and break the program into several parts and blocks using function. C is a Mother language because base for other programming language.C language is also considered a several concepts like function, constructor, pointer etc. C is a Mid -level language bcz consider the feature of low-level and high-level p...