My dear reader and visitors ,today we will learn more about what is Variable in C language and how to we use in program. What is variable initialization in C with example? What is variable declaration give one example of it?
- Compile Time Initialization or Static Initialization.
- Run Time Initialization or Dynamic Initialization.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int num=200;
printf("%d",the value of num);
getch();
}
Run Time Initialization or Dynamic Initialization
To assign value at run time from user is called run time initialization. For this purpose we use scanf() function in C language.For example-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int num;
scanf("%d",&num);
printf("the value of num=%d,num);
getch();
}
- Local Variable
- Global Variable
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
/* Local variable Declaration */
int num;
scanf("%d",&num);
printf("the value of num=%d,num);
getch();
}
Global Variable:-
A Global variables are the types of variable which are defined outside a function, usually on top of the program. We can accessed the global variable anywhere in the program or inside any of the functions defined for the program.For Example :-
#include<stdio.h>
#include<conio.h>
/* Global variable Declaration */
int num;
void main()
{
clrscr();
scanf("%d",&num);
printf("the value of num=%d,num);
getch();
}
Learn more about
How many types of casting are there in Java?
What is the difference between explicit and implicit casting in Java?
What are implicit and explicit casting explain with the help of example Java?
I hope you know what is Variable C language ? / What is variable initialization in C with example? What is variable declaration give one example of it? Must have understood very well. If you have any doubts in this blog, then you can write for it in the below comment box. There is one more request from you that you must tell your friends about this blog and share it on as many social media accounts as Facebook, What's app or others.