Exercise 1-2 (Print escapes)
Chapter_1 Exercise_1-1 | quotes Exercise_1-3 |
Exercise 1-2 K&R, p. 8
Exercise 1-2. Experiment to find out what happens when printf()'s argument string contains \c, where c is some character not listed above.
helloc.c download
#include <stdio.h> // for printf()
int main()
{
printf("Hello,\t\'world!\b\'\n");
}
/*
gcc helloc.c
./a.out
Hello, 'world'
*/
Notes:
\t is tab,
\b is backspace,
\' produces
',
!\b deletes
!
You could also include \"
for quotes within the quoted string argument of
printf(), as in
printf("Hello, \"world!\"\n");
which produces the output
Hello, "world!"
You can also include \f
(form feed),
\v (vertical tab),
\r (carriage return) or other
escape_sequences.
See also quotes,
Exercise_1-10, and
Exercise_3-2.
Chapter_1 Exercise_1-1 | BACK_TO_TOP | quotes Exercise_1-3 |
Comments
Post a Comment