C Programming Examples Tutorial Index

C Variable Programs

In this tutorial, a basic C program is demonstrated to print the values of predefined variables on the screen as output. The primary aim of this C program is to explain to beginners how to declare variables and print them using the printf() function.



/* C Program to Declare a Variable and Print Its Value */

#include <stdio.h>

void main ()
{
  int a = 9, b = 10; /* declaration of integer types variables */
  float c = 5.5, d = 15.5; /* declaration of floating types variables */

  printf ("Values of integer variables are: \n");
  printf ("%d\n%d \n", a, b); /* printing integer types of variables using format specifier (%d) */

  printf ("Values of floating variables are: \n"); /* printing float types of variables using format specifier (%f) */
  printf ("%f \n%f", c, d);
}

Program Output:

Values of integer variables are: 
9
10 
Values of floating variables are: 
5.500000 
15.500000


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram