Simple example to explain how variables are used.
Syntax:
int num;
float decimal;
char alphabet;
double number;
Here int, float, char and double are datatypes(type of data).
Here num,decimal,alphabet, number are variables. They may have any name.
Example describes getting two values from user and their addition .
#include<stdio.h>
int main()
{
int num1,num2;// Global declaration
printf("Enter the first number");
scanf("%d",&num1);
printf("Enter second number");
scanf("%d",&num2);
add(num1,num2);//Passing value to a function "add()"
return 0;
}
void add(int x,int y)
{
int total; // local variable
total = x + y; // performing actual addition
printf("The addition of two number is: %d",total); //Displaying addition of two numbers on screen
}
Output:
The addition of two number is: 5
Description:
Here we have used two types of variables.
1.Local variable (ex : total,x,y...)
2.Global variable (Ex: num1,num2)
We make those variable as global variable which we need to use throughout the code.
We make those variables as local variable which we would require very few times.
เคฎเคฐाเค ीเคค เคตเคฐ्เคฃเคจ:
เคเคค्เคคเคฐ:
The addition of two number is: 5
เคตเคฐ्เคฃเคจ:
เคเคฅे เคฆोเคจ เคช्เคฐเคाเคฐเคे เคตเคฐिเค
เคฌ्เคฒे เคตाเคชเคฐเคฒे เคเคนेเคค.
เฅง.เคฒोเคाเคฒ เคตเคฐिเค
เคฌ्เคฒे
เฅจ.เค्เคฒोเคฌเคฒ เคตเคฐिเค
เคฌ्เคฒे.
เคฒोเคाเคฒ เคตเคฐिเค
เคฌ्เคฒे เคฎ्เคนเคฃเคे เค्เคฏांเคจा เคฎเคฐ्เคฏाเคฆिเคค เคाเคेเคคเค เคตाเคชเคฐू เคถเคเคค.
เคเคงเคฐเคฃाเคค: total ,x , y.
เค्เคฒोเคฌเคฒ เคตเคฐिเค
เคฌ्เคฒे เคฎ्เคนเคฃเคे เคคे เคตเคฐिเค
เคฌ्เคฒेเคธ เค्เคฏांเคจा เคोเคกเค्เคฏा เคुเค เคฒ्เคฏा เคนि เคญाเคेเคค เคตाเคชเคฐू เคถเคเคคो.
เคเคงเคฐเคฃाเคค: num1,num2.
Comments