O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Printing Variables

Printing the values of variables will make use of the printf() function, which was used in Chapter 1 for creating a simple message. Sadly, you cannot simply place the variable names within the context of the message in order to print their values. Instead, you make use of different signifiers, which act as placeholders for the variables, and then follow the message itself with the list of variables to use. For example, the %d flag represents an integer:

int dob = 1947;
printf ("You were born in the year %d.",
 dob);

When the application is run, the value of dob will be used in place of %d, resulting in the message You were ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required