Variable:- C variable provide us name storage that our programs can manipulate.
The value of C variable may be change in the program. C variable uses
various types of Data Types such as int, char, float etc
1) Variable name must begin with letter or underscore (i.e sum, saf, float or flo_at, Safal_123 etc).
2) Variable names are case sensitive (i.e hello and Hello have different meaning)
3) No special symbols are allowed other than underscore (i.e Safal*,saf@ is not allow to declare variable)
#include<stdio.h>
#include<conio.h>
int b;//Global variable
void main()
{
int a,c;//Local variable
clrscr();
printf("enter the two number");
scanf("%d %d",&a, &b);
c=a+b;
printf("sum of two number = %d ",c);
getch();
}
Declaration: –
Data_type variable_name
e.g:- int a Some important rules for naming variables:-1) Variable name must begin with letter or underscore (i.e sum, saf, float or flo_at, Safal_123 etc).
2) Variable names are case sensitive (i.e hello and Hello have different meaning)
3) No special symbols are allowed other than underscore (i.e Safal*,saf@ is not allow to declare variable)
Types of variable: –
There are two types variables1) Local variable: –
Local variable is a variable that is declared inside the function and cannot be accessed out the function is known as local variable2) Global variable: –
Global variable is a variable that is declared outside the function and can be accessed outside or inside the function is known as Global variable.Simple example of Local variable and Global variable
//Write a program to print sum of two numbers#include<stdio.h>
#include<conio.h>
int b;//Global variable
void main()
{
int a,c;//Local variable
clrscr();
printf("enter the two number");
scanf("%d %d",&a, &b);
c=a+b;
printf("sum of two number = %d ",c);
getch();
}
No comments:
Post a Comment