# Test presentation 1
# C tutorial - C variables
So basically variables are named location in memory where program can manipulate(操作?). It is a way to represent memory location through symbol so that it can be easily identified. There are three types of variables in C, in different use. (Local, global and static variables).
There are some rules for defining variables.
- must start with alphabets or underscore only.
- but variables can have a digits.
- variable name must not use reserved word or keyboard. (int, char etc...)
Example of declaring variables.
> int a;
> char _b;
> float d12;
here is int, char floats are data types. a, _b, d12 are variables that we are trying to declare.
> int a=1;
> float b=11.1;
> int d=22,c=33;
we also can give values to the variables. in last line we declared 2 variables of integer type.
## Type of Variable
1. Local variable
A variable that is declared inside the function or block. It must be declared at the start of the block.
Example:
```
#include <stdio.h>
int main () {
/* below is local variable */
int a, b;
int c;
/* initialization */
a = 10;
b = 20;
c = a + b;
printf ("value of a = %d, b = %d and c = %d\n", a, b, c);
return 0;
}
```
output:
> value of a = 10, b = 20 and c = 30
2. Global variable
The variables declared outside any function are called global variables. They are not limited to any function. Any function can access and modify global variables. Global variables are usually written before main() function.
EXAMPLE:
```
#include <stdio.h>
/* global variable below */
int c;
int main () {
/* local variable declaration */
int a, b;
/* initialization */
a = 10;
b = 20;
c = a + b;
printf ("value of a = %d, b = %d and c = %d\n", a, b, c);
return 0;
}
```
OUTPUT:
> value of a = 10, b = 20 and c = 30
3. Static variable
Static variables are initialized only once. Static variables can be defined inside or outside the function. They are local to the block. The default value of static variables is zero. The static variables are alive till the execution of the program.
EXAMPLE:
```
#include <stdio.h>
int main() {
auto int a = 10;
static int b = -9;
printf("The value of a : %d\n", a);
printf("The value of b : %d\n",b);
if(a!=0)
printf("The sum value of both variable : %d\n",(b+a));
> []
return 0;
}
```
OUTPUT
> The value of a : 10
The value of b : -9
The sum value of both variable : 1