Sunday, May 5, 2013

Why variable are important?

You will frequently want your program to "remember" a value. For example, if your program requests a value from the user, or if it calculates a value, you will want to remember it somewhere so you can use it later. The way your program remembers things is by using variables. For example:
int b;
This line says, "I want to create a space called b that is able to hold one integer value." A variable has a name (in this case, b) and a type (in this case, int, an integer). You can store a value in b by saying something like:
b = 5;
You can use the value in b by saying something like:
printf("%d", b);
In C, there are several standard types for variables:
  • int - integer (whole number) values
  • float - floating point values
  • char - single character values (such as "m" or "Z")

Example

#include<stdio.h>
#include<conio.h>
void main()
{
    int a, b, c;      //these are variables 
    printf("enter two value");
    scanf("%d%d",&a,&b); 
    c = a + b;
    printf("%d + %d = %d\n", a, b, c);
    getch();
}

No comments:

Post a Comment