Variable Declaration and Printing in C Language

Variable Declaration and Printing in C Language

Introduction:
Building upon the foundational understanding of input and output operations, this assignment delves deeper into the realm of variable declaration and printing. Variables are the building blocks of any program, serving as containers for data, and this assignment introduces the manipulation of both integer and floating-point variables.

See Also – Multiple Variable Declaration

See Also – Introduction to printf and scanf in C

Description:
The program introduces the concept of variables, which are memory locations used to store data. Specifically, an integer variable age and a floating-point variable height are declared and initialized with predefined values. The program then utilizes printf to display these values, providing insight into how data is presented in the output.

The %d format specifier in the printf function is crucial here, as it dictates the format in which the integer value should be displayed. Similarly, the %f format specifier is used for the floating-point variable, allowing for control over the precision and appearance of the output.

Theory:
Variable declaration and initialization are fundamental concepts in programming. Variables serve as containers for storing data, and in C, each variable must be declared with its data type. The %d format specifier in printf is used for integers, while %f is employed for floats, allowing developers to control the appearance of these values in the output.

Program:

#include <stdio.h>

int main() {
    int age = 25;
    float height = 5.9;

    printf("Age: %d\n", age);
    printf("Height: %.2f feet\n", height);

    return 0;
}
Variable Declaration and Printing

Output:

Age: 25
Height: 5.90 feet
Variable Declaration and Printing
Mahesh Wabale
Latest posts by Mahesh Wabale (see all)

Leave a Comment