C Programming/Basic Output

Objective

 * Learn how to output text to the console.

Lesson
Output is information that the program tells the user. The most basic way to do this is writing text to the console. In the previous lesson, we output text to the console using the following program:

If you compile the above program and run it, you will get this output:



The function  is an input function that waits for the user to tap any key on their keyboard and returns a   representing that key. You will learn about input later on in this course.

The line in the above example code that says  is the one that outputs the Hello world! text to the console. is reading what is called a string. In this case, the string is the  part, including the double quotes. You can write almost any text you want.

Escape sequences
tells the console to start a new line. falls under a category called escape sequences. These are commands denoted by the backslash. If you removed "\n" from the first  call in the previous example, the second   would not be printing on a new line, and you would see the following: A65

This is because there is nothing telling the console to put a new line between "A" and "65".

Here is a table of most of the escape sequences.

* For both Hexadecimal and Octal number escape sequences, \nnn or \xnnn evaluates to a character with character code nnn. For example, \101 evaluates to the character A, as A has the character code of 101 in octal format.

Examples

 * Example 1: Some Odyssey

Assignments

 * Exercise 1: Quoth the Raven.