0% found this document useful (0 votes)
6 views1 page

Understanding Variables and Constants in C

The document provides an analysis of a C program that calculates the area of a circle using a defined constant for PI and variables for radius and area. It distinguishes between variables, constants, literals, and identifiers, explaining their roles in the code. The conclusion emphasizes the differences between these elements in programming.

Uploaded by

aashish727746
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)
6 views1 page

Understanding Variables and Constants in C

The document provides an analysis of a C program that calculates the area of a circle using a defined constant for PI and variables for radius and area. It distinguishes between variables, constants, literals, and identifiers, explaining their roles in the code. The conclusion emphasizes the differences between these elements in programming.

Uploaded by

aashish727746
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

Learning Activity 1 - Problem Based Activity

Code Given:
#include <stdio.h>
#define PI 3.14

int main() {
int radius = 5;
float area;
area = PI * radius * radius;
printf("Area of circle is: %.2f\\n", area);
return 0;
}

Analysis:

1. Variables:
- radius (int variable, stores value 5)
- area (float variable, stores calculated area)

2. Constants:
- PI (defined using #define, value = 3.14)

3. Literals:
- 5 (integer literal, assigned to radius)
- 3.14 (floating-point literal, assigned to PI)
- "%.2f\\n" (string literal, format specifier in printf)

4. Identifiers:
- main, radius, area, PI, printf (names given to elements in the program)

Conclusion:
- Variables are storage locations whose values can change.
- Constants hold fixed values throughout the program.
- Literals are actual fixed values used directly in code.
- Identifiers are user-defined names given to variables, constants, functions, etc.

You might also like