Skip to main content
Contents Index
Search Book
Search Results:
No results.
Readability settings Prev Up Next
\(\newcommand{\N}{\mathbb N}
\newcommand{\Z}{\mathbb Z}
\newcommand{\Q}{\mathbb Q}
\newcommand{\R}{\mathbb R}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 4.10 The char Datatype
So far we have only stored integer numbers in variables.
You can also store letters or symbols in variables (in computer speak these are called
characters ).
The datatype to store a character is called
char, the format specifier is
%c
Activity 4.8 . printf Practice.
Write a program that prints out βENGS 20β using the following
printf() statement:
printf("%c%c%cS 20\n", letter1, letter2, letter3);
Please do not make any changes to the
printf statement since the autograder will not function correctly if you do.
Reading characters from the user input.
You can use
scanf() to read a character from the user input:
Investigate 4.9 .
What do you think would happen if you tried to use the
scanf() function to read a character, but you use the format specifier for an integer-type variable,
%d? Will it work or fail?
Hint .
Take your best guess, and then feel free to try it out in the code window above
So far we have only stored integer numbers in variables. You can also store letters or symbols β
characters .
The datatype is
char and the format specifier is
%c:
You can use
scanf() to read a character from the user input:
When you are finished, please paste the code you added here.