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

Introduction to Characters

The main data types used in C, including numbers, strings, and arrays, will each have its own chapter in this book, but a more basic type, the character, deserves a little discussion as well. Unlike the number types, character variables can be used for non-numeric characters such as letters and punctuation.

Creating a character variable is easy:

char initial;

Assigning values to character variables is only slightly more complicated, requiring the use of single (straight) quotation marks:

char right_answer;
right_answer = 'D';

Notice that a simple char variable contains only a single character. In the next section you'll learn how to make longer chars.

To print the value of a character using the printf() function, ...

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