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.
Prerequisites
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.
1 2 3 4 5 6 7 8 9 10 11 12 |
#include <stdio.h> void main() { 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); } |
Output:-
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).