0% found this document useful (0 votes)
42 views2 pages

Untitled Document 20

In C programming, a variable is a named storage location that can hold a value which may change during execution, while a constant is a fixed value that cannot be altered. For example, 'int age;' defines a variable, and 'const int MAX_AGE = 100;' defines a constant. The key difference is that variables can be modified, whereas constants remain unchanged throughout the program.

Uploaded by

altaftamboli671
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views2 pages

Untitled Document 20

In C programming, a variable is a named storage location that can hold a value which may change during execution, while a constant is a fixed value that cannot be altered. For example, 'int age;' defines a variable, and 'const int MAX_AGE = 100;' defines a constant. The key difference is that variables can be modified, whereas constants remain unchanged throughout the program.

Uploaded by

altaftamboli671
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Q.Define variable? Define constant?

Give the difference between variable & constant with


suitable example.

In C programming, a variable is a named storage location in memory that holds a value,


which can be modified during the program's execution. Variables are fundamental for
storing data that can change over time.

Defining a Variable:

To define a variable, specify its data type followed by its name:

int age;

Here, age is a variable of type int (integer).

Assigning a Value to a Variable:

Variables can be assigned values using the assignment operator (=):

age = 25;

This assigns the value 25 to the variable age.

Constants:

A constant is a value that cannot be altered during the program's execution. Constants
are used to represent fixed values that do not change, enhancing code readability and
maintainability.

Defining a Constant:

Constants can be defined using the const keyword or the #define preprocessor directive:

const int MAX_AGE = 100;

or

#define MAX_AGE 100

In both cases, MAX_AGE is a constant with a value of 100.

You might also like