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 ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.