C Declare Multiple Variables
1. What is Declaring Multiple Variables?
-
In C, you can declare more than one variable of the same type in a single line.
-
This is called multiple variable declaration.
Syntax:
Example:
Here, we declared 3 integers, 3 floats, and 2 characters in a single line each.
2. Declaring and Initializing Multiple Variables
You can also assign values while declaring:
3. Example Program
Output:
4. Notes and Best Practices
-
Same Data Type: Only variables of the same type can be declared together.
-
Separate Initialization: You can also declare first, then assign values later:
-
Readability: Don’t declare too many variables in one line; it can reduce code readability.
5. Quick Tip
-
Use multiple declaration to save space and organize related variables, especially in short programs.
-
For larger programs, declaring each variable on a separate line improves clarity.
