C++ Basics

C++ is great for large performance-sensitive p
rojects or for coding desktop applications. It’s much easier to screw up with this language, but the provided functionality and possibility becomes quite useful for said projects. Plus, the sheer number of libraries is neat, I have barely used a tiny fraction of them myself. Just as a side note I made this to specifically to help people pass coding 1 and maybe 2 (if I have the time).

First all normal syntax in c++ ends in “;” with exceptions of functions.

Data Types

There are many data types in c++, and the ones that you will most likely use are:

    int – used to declare an integer variable, you can have an array of characters by declaring int NAME[length]
    char – used to declare a character variable, you can have an array of characters by declaring char NAME[length]
    string – used to get a bunch of chars as one variable, you can have an array of characters by declaring char NAME[length]
    float and double – used as precision integers, they can go into decimal places, arrays of them also available

The int main() and Basic Headers

Whenever you write a c++ program, you should always have


This is because they are the basic input, output, and other built in functions, without them, the program would have no idea what you are talking about, and therefore never be able to do anything. Also, all c++ programs have this:


int main is the main function of the program, and it is where the program basically starts it’s actual functioning and starts on its work.

Basic Operations

First and foremost, you need the input and output functions, cin and cout respectively. Sample code:


Note that you must always use “>>” for cin and “<<” for cout, and the endl at the end of the output statement creates a new line.


Now you should be ready to learn if and switch statements.


The if statement is basically saying “if this is true or this happens, this other thing in the curly brackets happen”
The switch statement is basically another type of if statement.


For loops allow you to execute a command a number of times, count, or course through an array.


the “<” before the ending_point could be changed to <=, >=, or > according to the function of the loop. Also, the ++ could be changed to += any_number, –, or -= any_number. Another thing you should keep in mind is that the “variable<ending_point” could be ignored entirely to create an infinite loop, something you might or might not want depending on what you feel like doing. An example of a for loop with int i:


This loop starts at 0, then goes all the way to 99 (<100), going up by 1.


Now for the while and do-while statements:


while first checks whether a condition is true, if it is, it executes the stuff and then checks if the condition is true again. The do-while statement first does the actions THEN checks if the condition is true. Now that I’ve covered pretty much the conditional statements, it time to get to the for loop, which is what you are going to use for coding 1.

Hello World example


What Do You Think on This ? Say Here