woensdag 23 september 2020
Hi welcome to my journey through C programming!
I know this might be cliché but everywhere you look as a beginning programmer you start with this little piece of code called “Hello World”
Its easy to start you of with programming, but it gives you very little information and it tells you nothing about what is happening.
So lets change that. Here we go.
When creating a program, any program, you start with this little line of code: #include <stdio.h>.
The stdio.h is a header file and you need it to tell your program various things to help it function.
There are various normalized header files that can be accessed this way and we will see some of those on this journey through C.
We use the #include to include header files.
There are 2 ways to include header files.
The stdio.h header is a sort of library that contains variable types, macros and functions to make your programming life easier.
Its name stdio stands for standard input output and it contains the printf function.
The standard input by default is your keyboard and shall from now on be referred to as stdin.
The standard output by default is your display monitor and shall from now on be referred to as stdout.
The int main(void) is a function that is present in every C program and is the point where every C program starts.
Every function is formatted in a specific way:
The return type specifies the type of variable a function returns.
In this case the return type is int short for integer and it tells the function that it should return a number.
The function name can be almost anything you want it to be, but there are a few rules that have to be followed.
so why cant a function name start with a number?
The reason is that the C compiler considers the whole token to be a number if the first character is a digit.
Also its good to note that although it is allowed to use a underscore to start a function name it is allmost never used because underscores are often used as the starting character for names of extra variables declared by the assembler over which the compiler has no control. This can lead to conflicts and problems.
The parameters are variables that are being passed on to the function.
The printf() function is very commonly used in C there are other functions that also can be used like puts() and write()
For now we will stay with the printf() function, the printf() function prints a string of characters to your stdout.
You can do a lot of things with the printf function and we will go in to further detail on a later post.
Here it just prints a string of hard coded characters.
The return (0); is used to return a value after the function has done its job or in case of the main function it returns a 0 when the program has run its course.
So now you know what everything means, do we know in depth what it means no there is much more to learn but it would be too much to deal with right away.
I already feel like I went to far into the deep end with somethings.
If you’d like to, you can make a couple of exercises on your own.
I’ve taken the liberty to put some exercises down below so have at it.
Ok here are some guidelines and restrictions on how to make the exercises they are here for your benefit.