Data types

C language type of variables with example

C language type of variables with example

In this tutorial, we are going to discuss the concept of ” C language type of variables with example.

Variable is a fundamental concept in programming languages to store data in the memory location. We should clearly understand it before learning the program.

C language type of variables

Variables are used to indicate the memory location and should be given a unique name (identifier).

The name of the variable is an identifier of the memory location and it is just the symbolic representation of a memory.

Different types of variables require a different amount of memory for functioning with a set of operators

 

C language type of variables

how to declare  a variable

Syntax

Data_Type varaible_Name list;(use one or more variable)

The name of the variable can contain alphabets (both upper case or lower case), numbers and the underscore. but the variable name does not start with a  number.

Here, we can see some of the variable and their declaration in C language

int– integer type

integer variable types are numeric numbers that hold positive, negative and zero values. int is a keyword in C language

Example

0,-5,8

 

How to declare an integer data type in C language – int

For example

int age;

here, int is a data type, age is a variable

 

int age,marks;  //declaring two variables as same type

Here, age and marks are both variables and  integer data type as well

 

Declaration and initiation of integer variables

int age=23;

Here, age is an integer data type and holds the value of 23;

int age=23,marks=67;

Here, age, marks are an integer data type and holds the value of 23,67 respectively;

 

float– floating point type

float variable types are the decimal values that hold real number values. in addition, it is a keyword in C language

Example

23.34, -5.34

 

How to declare float variable type in C language – float

Declaration of the float variable

float average;
double blance;

Here, the average is a float data type.

the balance is a double data type

 

Declaration and initiation float variable type

float averageMarks=85.45;
double balanceMoney=345.50;

Here, averageMarks is a float variable type and holds the value of 85.45

balanceMoney is a float variable type and holds the value of 345.50

 

char– Character types

char variable is used to declare character type variables. in addition, it is a keyword in C language.

Example

‘S’

 

How to declare a character variable in C language – char

Declaration of the character variable

char alphabet;

Here, the alphabet is a char variable

 

Declaration and initiation of character data type

char alphabet='A';

Here, the alphabet is a char variable and it  bears a value ‘A’;

 

types of Variables  in C language

  1. local variable
  2. global variable
  3. static variable
  4. automatic variable
  5. external variable

local variable

the local variable is always  declared inside the function or block(it is mostly declared at the starting point of blocks or before using the variable);

The name variable is an identifier so, it must be declared and initialized before it is used.

Example

void function_Name(){
int a=5;
}

Global variable

A variable that is declared outside of function or block is called a global variable. the global variable is available for all the function inside a block and value of the global variable can be changed by any function.

int age=20;  //global variable
void function_Name(){
marks=56; //local variable
}

 

Static variable

a variable which is declared with the static keyword for a special purpose is known as static variable

void function_Name(){
int age=20  //local variables
static int marks=57;  //static variable
................................
................................
}

 

Automatic variable

the variable that is declared with the auto keyword is known as an automatic variable.

void function_Name(){
int age=20  //local variables
auto int marks=78;  //static variable
................................
................................
}

External variable

the variable that is declared with the extern keyword is known as an external variable. External variable functions like a global variable. We can use this keyword to  share multiple files as a global variable

external int age=23;

void function_Name(){
int age=20  //local variables
}

Rules of naming a variable

  • A variable name can have only a letter,(A,b), digits,(1,2,5) and underscore(_), but neither symbols nor characters can be used.
  • The first letter of a variable name should be either a letter or an underscore only
  • Blank is not allowed with the variable name
  • A variable name must not be any reserved word or keyword

Category of data types

Suggested for you
Data type in C language
Cpp programming language Data Types
Cpp programming variables and types
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Share
Published by
Karmehavannan
Tags: C language

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago