How To Store Data Value in Variables C Language
Variable: Variables are containers used to store a value in our program. A variable is a named area of memory where we can store and manipulate the values of our program.
The variable name can be chosen by the programmer in any meaningful way to reflect its function or nature in the program. The rules for naming variables are the same as for naming identifiers.
All variables are temporarily stored in random access memory called RAM. For this reason, they are automatically deleted upon completion of the function program.
Important Variable Topic in Other Languages
👉C++ Variables
👉Java Variables
👉Python Variables
There are some restrictions on variable names and symbolic constants.
Variables and constants are the main data objects processed by the program.
1. Variable Names are made up of letters and numbers.
2. The first character must be a letter.
An underscore is considered the letter "_" but does not start a variable name with an underscore.
3. Uppercase and lowercase letters are different, so v and V are two different names.
4. Traditional C practice is to use lowercase for the variable name and all uppercase for symbolic constants.
5. Keywords like other, int, float, etc. are Reserved, we cannot use them as a variable name.
6. The manifest lists the variables used and describes their types and, possibly, their initial values.
7. At least the first 31 characters of a local variable name are important. For function names and external variables, the number may be less than 31. For external names, the standard guarantees exclusivity for only 6 characters and one case.
How To Use Variable in C program?
#include<stdio.h> #include<conio.h> int main() { int id = 7834; char name[20]="icoderweb"; char gender = 'm'; float height = 6.4; printf(" Student ID No:%d",id); printf("Student Name: %s\n",name); printf("Student Gender:%c\n",gender); printf("Student Height:%.2f\n",height); return 0; } *****OUTPUT***** Student ID No:7834 Student Name:icoderweb Student Gender:m Student Height:6.4 |
How To Use Variables are case sensitive like lower and upper case letters are different?
int main()
{
int a ;
int A ;
a = 100;
A = 200;
printf("Value of a:%d\t",a);
printf("Value of A:%d",A);
return 0;
}
Value of A:200
Variables Types of C Programming Language
We are using basically two types of variables in the C Programming language.
1. Local variables
2. Global variables
1. Local variables are accessible only inside the function or block.
2. A global variable can be accessed anywhere within the program.
How To Use Local variables in C?
#include<stdio.h> #include<conio.h> int main() { { int a = 100; printf("Local variables value of a:=%d",a); } return 0; } *****OUTPUT***** Local variables value of a:100 |
How To Use Global Variables in C?
#include<stdio.h> int a = 100; int main() { printf("Global variables value of a:=%d\t",a); { int a = 30; printf("Local variables value of a:=%d",a); } return 0; } *****OUTPUT***** Global variables value of a:100 Local variables value of a:30 |