Home C Programming Language / Programs / Program to Demonstrate Constants in C Language
🚀 Programming Example

Program to Demonstrate Constants in C Language

👁 6 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

📌 Information & Algorithm

Algorithm

  1. Start the program.
  2. Declare an integer variable and assign a constant value.
  3. Declare a floating-point variable and assign a decimal constant value.
  4. Display both values using the printf() function.
  5. Observe the constants used in the program.
  6. End the program.

💻 Program Code

#include <stdio.h>

int main()
{
    int marks = 100;
    float percentage = 99.50;

    printf("Integer Constant = %d\n", marks);
    printf("Floating Constant = %.2f", percentage);

    return 0;
}
                        

🖥 Program Output

Integer Constant = 100
Floating Constant = 99.50
                            

📘 Explanation

A constant is a fixed value that does not change during the execution of a program. Constants can be numeric, character, or string values. They are one of the fundamental types of tokens in C programming.

In this program, the values 100 and 99.50 are constants because their values remain fixed throughout the execution of the program.

Constant Type Description
100 Integer Constant A whole number value without a decimal point.
99.50 Floating-Point Constant A numeric value containing a decimal point.

The statement int marks = 100; assigns an integer constant to the variable marks. Similarly, the statement float percentage = 99.50; assigns a floating-point constant to the variable percentage. Constants provide fixed values that can be used in calculations, assignments, and output statements.

Common types of constants in C include integer constants, floating-point constants, character constants, and string constants.

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.