In this tutorial you will learn about the C Program for Declaring a variable and Printing Its Value and its application with practical example.
In this tutorial, we will learn to create a program where we will be declaring a variable and printing its value using C programming language.
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- C Variables
- C Data Types
- C Input Output
Program for Declaring a variable and Printing Its Value
In this program, we will declare both integer and floating type variables and print their values using printf function.
int a=5,b=10; // declaration of integer types variables
float c=5.2, d=20.5; // declaration of floating types variables
printf("Values of integer variables: \n");
/*printing integer types of variables using format specifier (%d) */
printf("%d\n%d \n", a,b);
/*printing float types of variables using format specifier (%f) */
printf("Values of floating variables: \n");
printf("%f \n%f", c, d);
In the above program, we have first declared and initialized a set of both integer and floating type variables.
- a = integer type variable initialized with 5
- b = integer type variable initialized with 10
- c = float type variable initialized with 5.2
- d = float type variable initialized with 20.5
In the next section we have some printf statements to print values of the integer variables using integer format specifier(%d) and values of float variables using float format specifier(%f).