Variable Declaration in C programming

Variable Declaration in C

Variable Declaration in C

In C programming, declaring a variable involves specifying its type and name. The basic syntax for declaring a variable is:

type variableName;

Here’s what each part means:

  • type: Specifies the data type of the variable, such as int, float, char, etc.
  • variableName: The name of the variable, which must follow C's naming conventions.

Examples

Integer Variable

int age;

This declares an integer variable named age.

Float Variable

float salary;

This declares a float variable named salary.

Character Variable

char initial;

This declares a character variable named initial.

Multiple Variables of the Same Type

int x, y, z;

This declares three integer variables: x, y, and z.

Variable with Initial Value

int age = 30;

This declares an integer variable named age and initializes it with the value 30.

Note:
Ensure that variable names are descriptive and follow C's naming conventions, such as starting with a letter or underscore and not using reserved keywords.

Comments

Popular Posts