You are on page 1of 1

Q.4:- What is variable? Explain with example.

**Variable**:

A variable is a fundamental concept in programming that represents a storage location in a computer's


memory where data can be stored, retrieved, and manipulated during program execution. Variables have a
specific data type that determines the type of data they can hold, such as integers, floating-point numbers,
characters, or custom data structures.

**Example**:

Consider a simple C program that calculates the area of a rectangle:

#include <stdio.h>

int main() {

// Declaration of variables

int length, width, area;

// Assign values to variables

length = 5;

width = 3;

// Calculate area

area = length * width;

// Output the result

printf("The area of the rectangle is: %d\n", area);

return 0;

In this example:

- We declare three variables: `length`, `width`, and `area`, of type `int`.

- We assign the values `5` and `3` to the variables `length` and `width`, respectively.

- We calculate the area of the rectangle by multiplying `length` and `width`, and store the result in the variable
`area`.

- Finally, we print the calculated area using `printf()`.

Here, `length`, `width`, and `area` are variables that hold integer values. They serve as placeholders for storing
data that can be accessed and modified as needed during the execution of the program.

You might also like