But by now you are burning to actually program. So let's do the traditional 'hello world' program.
-----------------------------------------------------
#include "stdio.h"
void main( ){
printf("Hello World!\n");
}
---------------------------------------------------------
That may look all a bit puzzling to a beginner. So let's begin with the beginning. I said that functions were subsystems but the entire program itself is also considered to be a function, it's the main function. It has to be called 'main' so that the compiler would know where the program begins. Since functions are (sub)systems it should not be surprising they have the following structure.
<type of output> <name of function> ( <type of input> ) {
<actual code here>
}
In our case the type of output was void. Which means 'no specific type of output'. The name is main and in between the brackets there is the input; nothing in this case. The function itself goes from the opening curly bracket till the closing one.
In between the curly brackets I put printf. That means 'display a bit of text in the terminal'. Printf is itself a function. It was written by someone else, the body of the function is not visible here. It's being called, that means we want to make use of it here. In between the round brackets we put the input. Which is "Hello World!\n". The double quotes is used when dealing with text as opposed to numbers. The '\' means that the next character is not to be taken literally. The 'n' after that means take a new line.
The body of printf is not in the program but the compiler needs to be able to find it. That's why we write #include. The include tells the compiler we might be using the functions in our program that are described in "stdio.h", like printf.




Reply With Quote
Bookmarks