-
Notifications
You must be signed in to change notification settings - Fork 0
C_Constants.c
ani9977 edited this page Sep 11, 2024
·
1 revision
Here's the updated code with comments and explanations:
#include <stdio.h> // Includes the standard input-output library
#define PI 3.14159 // Defines a constant PI with the value 3.14159
int main() { // Main function where the program starts executing
printf("PI value: %f\n", PI); // Prints the value of PI using the %f format specifier for floating-point numbers
return 0; // Returns 0, indicating that the program has run successfully
}-
#include <stdio.h>: This line includes the standard input-output library which allows the use of functions likeprintf. -
#define PI 3.14159: This is a preprocessor directive that defines a constantPIwith a value of3.14159. The#definekeyword allows you to create symbolic constants in C. -
int main(): The main function is the starting point of the program. -
printf("PI value: %f\n", PI);: Theprintffunction prints the value ofPIto the console. The%fformat specifier is used to display floating-point numbers. -
return 0;: This indicates that the program executed successfully.
Using #define to define constants like PI allows for more readable and maintainable code, as it avoids magic numbers (hardcoded values) scattered throughout the program.