Lesson 3

2

Now that we have learnt about variables and printing out text to the console, we are ready to create our first project in Dev-C++!

Follow these steps and then we will write the code together!

Once you are done saving the project you should see your code in the editor!

Now let's edit this code a little bit and do something.

Notice that we have specified int argc, char *argv[] as arguments of the main function. Don't worry about that for now, it will work anyways and we will talk about what this is later in this course!

Our code now has three int variables called sum, num1 and num2, all of which are initialised with the value $0$.

On the lines below we are giving num1 the value of 12 and num2 the value of 13. sum has the value of num1 + num2 (and as we know, $12 + 13 = 25$). We will discuss the arithmetic symbols later in this course!

Then we simply use a printf function call to output our result. We use %d three times and then enter the arguments in the correct order.

You can also see that I have written a comment in the code. A comment is something you write to help yourself and others remember and explain what you have done to make it easier understanding the code. This text will not be seen by the compiler and will not affect your code in any way. You can write comments using double slash (//) or by using slash + star (/*). For example:

When your program is done, go ahead and click the square on the top of the IDE ("Compile and run"). Save your project first and then it will run!

You can see that the result of this in the console window in the picture.

At the bottom of our IDE we have a compiler log. This tells us if we get any errors when trying to compile the program, or if we have any warnings. If you forget a semicolon for one instruction, this is where the error will be shown. It is a common mistake to forget semicolons or other syntax related things when you are a beginner, but it does not matter, it happens all the time!

In the next chapter, we will discuss arithmetic operators!