---
title: "Constants and variables"
subject: "Computer Programming"
chapter: 3
key: "semester_1/computer_programming:constants-and-variables"
source: https://www.bctengineer.com/q/semester_1/computer_programming/constants-and-variables
site: BCT Engineering
---

# Constants and variables

Computer Programming · Chapter 3: Introduction to ‘C’ programming

- Asked in: 2071 Chaitra, 2 marks
- Video: [01 - VARIABLES & CONSTANTS in C PROGRAMMING](https://www.youtube.com/watch?v=aUqO-dgzMw4) — Sundeep Saradhi Kanthety
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/constants-and-variables
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-3

## Question

Explain constants and variables.

## Short answer

Constants are fixed values that do not change (integer, real, character, string). They can be defined with #define or const. Variables are named memory locations holding values that can change; they must be declared with a specific data type before use.

## Answer

**Constants** are fixed values that do not change during execution. They are of types integer (`25`), real (`3.14`), character (`'A'`) and string (`"Hello"`). They can be named with `#define PI 3.14` or `const int DAYS = 7;`.

**Variables** are named memory locations that store data which can change during execution. They must be declared with a type before use: `int count = 0; float avg;`. Variable names follow the rules of identifiers.

Example:
```c
#include <stdio.h>
#define PI 3.14159
int main(void)
{
    const int DAYS = 7;       /* constant */
    int count = 0;            /* variable */
    float radius = 2.0f;
    count = count + DAYS;
    printf("%d %.2f\n", count, PI * radius * radius);
    return 0;
}
```

Output:
```text
7 12.57
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which statement describes a constant?
   A. Its value can change during execution
   B. Its value is fixed during execution
   C. It needs no value
   D. It is always an integer
   Answer: B. A constant does not change during execution. (Key point: Constant)

2. Which of these is a character constant?
   A. "A"
   B. 'A'
   C. A
   D. 25
   Answer: B. Character constants are written in single quotes; "A" is a string. (Key point: Constant types)

3. What must be done before a variable is used?
   A. It must be declared with a type
   B. It must be written in capitals
   C. It must be a #define
   D. Nothing
   Answer: A. Variables must be declared with a data type before use. (Key point: Variable declaration)

## Related in Computer Programming

- [FORTRAN constants, variables, library functions](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-constants-variables-library) — Computer Programming, chapter 11

## Related in other subjects

- [Penman equation and its variables](https://www.bctengineer.com/question.md?key=semester_5%2Fengineering_hydrology%3Apenman-equation-variables) — Engineering Hydrology, chapter 3
