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.
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’;
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; }
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 }
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 ................................ ................................ }
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 ................................ ................................ }
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 }
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…