C Variables
A variable is a data name that may be used to store a value. Unlike constant variables are also remain unchanged during the execution of a program. A variable name should be chosen in a meaningful way so that it relects its function or nature in the program. There are some rules for choosing a variable name. They are following:
- Must begin with a letter or underscore.
- First 31 characters are significant.
- Variables name are case sensitive.
- consist of Capital letters(A-Z), lowercase letters(a-z), digits(0-9), and the underscore character.
- Should not be a keyword.
- White space is not allowed.
- Special characters are not allowed.
There are the following variable types in C language:
Type | Description |
---|---|
char | Used to store characters and letters |
int | Used to store an integer. |
float | Used to store single-precision floating point value. |
double | Used to store double-precision floating point value. |
void | Comprises an empty set of values. |
Example of a c program using variable is given below:
Example
#include <stdio.h>
int main()
{
int first_number, second_number, sum;
printf("Enter two integers: ");
scanf("%d %d", &first_number, &second_number);
sum = first_number + second_number;
printf("%d + %d = %d", first_number, second_number, sum);
return 0;
}
Output:
Enter two integers: 7 17 7 + 17 = 24