About Lesson
Variables:
- A Variable is Nothing, but a name given to a Storage Area that our programs can manipulate.
- Each variable in C has a specific type, which determines the Size and Layout of the Variable’s Memory; the Range of Values that can be stored within that Memory; and set of operations that can be applied to the variable.
- The Name of a variable can be Composed of Letters, Digits, and the Underscore Character.
- It must begin with either a Letter or an Underscore, Uppercase and Lowercase Letters are distinct because ‘C‘ is Case-Sensitive.
Type of Variables Support by ‘C’ Language:
1. Primary (Built-in) Data Types:
- int: Integer type, used for storing whole numbers.
- float: Floating-point type, used for storing numbers with a decimal point.
- double: Double-precision floating-point type, used for storing larger decimal numbers.
- char: Character type, used for storing single characters.
Example:
int age = 25;
float salary = 55000.50;
double pi = 3.14159265359;
char grade = ‘A’;
2. Derived Data Types:
- Arrays: Contiguous memory locations to store multiple values of the same data type.
Example:
int numbers[5] = {1, 2, 3, 4, 5};
- Pointers: Variables that store memory addresses.
Example:
int a = 10;
int *p = &a; // p now holds the address of variable a
- Structures: User-defined composite data type that groups variables of different types under a single name.
Example:
struct Person {
char name[50];
int age;
};
- Unions: Similar to structures, but all members share the same memory location.
Example:
union Status {
int errorCode;
char message[100];
};
3. Enumeration Data Type:
- enum: User-defined data type that consists of named integer constants.
Example:
enum Days {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
4. Void Data Type:
- void: Used to indicate that a function returns no value or that a pointer does not point to any specific type.
Examples:
void printMessage() {
printf(“Hello, world!n”);
}void *genericPointer;