Variables in C Programming Language.c
Variables in C Programming Language.c
A **variable** in C is a named memory location used to store data that can change during program
execution. Variables are a fundamental concept in C, enabling programmers to manipulate data
efficiently. Here's an overview of variables in C, covering their types, declaration, and usage.
---
- **Name**: Each variable has a unique name or identifier, adhering to C’s naming rules.
- **Type**: Determines the kind of data a variable can hold (e.g., integer, character).
- **Scope**: Defines where the variable can be accessed within the program.
- **Lifetime**: Specifies how long the variable exists during program execution.
- **Storage Class**: Describes the storage duration and linkage of the variable.
---
In C, variables must be declared before use. The syntax for declaration is:
```c
data_type variable_name;
```
- Example:
```c
```
```
---
- Arrays
- Pointers
- Structures
- Unions
**c) Enumeration**
**d) Void**
---
```c
int y;
```
---
Variables can belong to different storage classes, affecting their scope and lifetime:
- **Automatic (auto)**: Default for local variables; created and destroyed within a block.
---
- **Local Variables**: Declared within a block or function, accessible only inside it.
- **Global Variables**: Declared outside any function, accessible throughout the program.
- **Static Variables**: Retain their value across multiple function calls within the same file.
---
```c
include <stdio.h>
int globalVar = 10; // Global variable
void display() {
staticVar++;
int main() {
display();
return 0;
```
**Output:**
```
Global Variable: 10
Local Variable: 20
Static Variable: 5
Static Variable: 6
```
---
---
**Conclusion**
Variables are an essential concept in C programming, allowing for data manipulation and efficient
memory usage. By understanding variable types, scope, storage classes, and proper naming
conventions, programmers can create robust and optimized programs.