C – Language

Declaring Multiple Variables in C

  1. Declaring Multiple Variables

Sometimes you need to create more than one variable of the same type.
Instead of writing them in separate lines, you can declare them in one line using commas ,.

Example:

int x = 5, y = 6, z = 50;

printf(“%d”, x + y + z);

✅ Output:

61

👉 Explanation:
Here,

  • x = 5
  • y = 6
  • z = 50
    x + y + z = 61
  1. Assign Same Value to Multiple Variables

You can assign the same value to multiple variables of the same type in a single statement.

Example:

int x, y, z;

x = y = z = 50;

printf(“%d”, x + y + z);

✅ Output:

150

👉 Explanation:
All three variables get the value 50.
So, x + y + z = 150

 Quick Summary

Concept

Description

Example

Output

Multiple variable declaration

Create many variables in one line

int a = 1, b = 2, c = 3;

6

Assign same value

Give same number to many variables

a = b = c = 10;

30