Saturday, 8 August 2026

Multiple Variables in C

 To declare more than one variable of the same type, use a comma-separated list:

Example

int x = 5, y = 6, z = 50;
printf("%d", x + y + z);

Note: All variables must be of the same type. You cannot mix types in the same declaration.

You can also assign the same value to multiple variables at once:

Example

int x, y, z;
x = y = z = 50;
printf("%d", x + y + z);

Tip: Declaring multiple variables on one line is convenient, but declaring them on separate lines can make your code easier to read.

No comments:

Post a Comment