C tutorial

Part 3


PRINTF

The function "main" was defined last time. But returning 0 doesn't do very much of note. So perhaps something more interesting shall be done.

printf("Hello world.");

This shall be added to "main" right above the return 0. If you remember, return 0 exits the function, so it would exit the function before it executed this statement here. A value enclosed in quotes here (double quotes specifically) is a string. This is another type. Except not really, C doesn't have strings, C has char*. What exactly that means is the next thing, it is a pointer to a char(acter), you don't need to understand that just yet.

"printf" is a function that we are calling, you call the function by writing its name and then whatever values it asks for in parentheses. And again, this is a statement and so it ends in a semicolon. Printf can also do more interesting things but for now that is a later thing.

If we wanted to call "main" we would simply put:

main();

But that's not a good idea. Your compiler will probably yell at you if you try that. This is just an example.