Extreme Hacking | Sadik Shaikh
Advanced Ethical Hacking Institute in Pune

 

This is a Basic Mode Notes for C++, more detail notes are in process. Stay tunned..
This tutorial will thoroughly cover…
Structure of a Basic Program
Comments
Variables. Data Types.
Identifiers
Fundamental data types
Declaration of variables
Scope of variables
Initialization of variables
Introduction to strings
Constants
Literals
Integer Numerals
Floating Point Numbers
Character and string literals
Boolean literals
Defined constants (#define)

  • Structure of a Basic Program

In my opinion, the best way to start learning a programming language, is to create the simplest program, and then go over what everything is. The previous program is the typical program that programmer apprentices write for the first time, and its result is the printing on screen of the “Hello World!” sentence. Below is the code used to create the “Hello World!” program.
Code:

// This tutorial was created by Sadik Shaikh
#include <iostream>
using namespace std;
int main ()
{
cout << “Hello World!”;
return 0;
}

It is one of the simplest programs that can be written in C++, but it already contains the fundamental components that every C++ program has. We are going to look line by line at the code we have just written:

// This tutorial was created by Sadik Shaikh

This is what is called a comment line. A comment line begins with 2 slash signs (//) and are there for either the developer or the learner to understand what the developer has added. It normally includes an observation of the source code, and doesn’t effect the program.

#include <iostream>

When a line begins with a hash tag (#), it is a directive for the preprocessor. They are not commands, but recognition for the compiler’s preprocessor. In our case, #include <iostream> presents the preprocessor to include the iostream standard file. iostream includes the basic input-output library in C++, and is included because functionality.

using namespace std;

All elements of standard C++ are declared within a “namespace”, with the name std. In order to access of the functionality, we can declare with this expression that we’re using these entities. This is very frequent in any C++ program that uses standard library, and will be included in most of this tutorials source code.

int main ()

This line is the beginning of the main function. The main function is the point where all C++ programs start execution, independently of the location in the source code. It doesn’t matter whether there are functions defined before or after it – the instructions contained within this function’s definition will always be first executed. For that reason, a function is essential in any C++ program. The word main is followed by a pair of parentheses ( () ) That’s because it’s a function declaration: In C++, what differentiates a function declaration from other types of expressions are the parentheses that follow its name. Optionally, they be enclosed with parameters within them. Right after the parentheses, we can find the body of the main function enclosed in braces ({}). Whatever is contained in the braces, is what the main function will do when it’s executed.

cout << “Hello World!”;

This line is a C++ statement. A statement is a simple or compound expression that can produce an outcome. Honestly, this statement preforms the only action that makes an effect in our program.

cout represents the standard output of C++, and the meaning of the statement is to insert characters (in this case the Hello World sequence is the screen). cout is declared in the iostream startard file within the std namespace, so that’s why we needed to include that specific file and to declare that we were going to use this specific namespace earlier in our code. Notice that the statement ends with a semicolon (Wink This character is user to mark the end of a statement, and must be included or else your source code will error (one of the most common syntax errors is indeed to forget to include some semicolon after a statement).

return 0;

The return statement causes the main function to finish. return can be followed by a code (in this case, it’s 0). A return code of 0 for the main function is generally interpreted as the program worked as expected without errors during execution. It’s the most usual way to end a C++ program.

If you haven’t noticed, not all the lines of our program preform actions when it’s executed. There were lines containing comments (began by //). There were lines with directives for the preprocessor (began by #). Then there were lines that began a function (like cout), which were all included in the black delimited by braces ({}) of the function. We structure it in different lines to make it more readable, but with C++, there’s no rules on how we seperate instructions. Instead of
Code:

int main ()
{
cout << ” Hello World!”;
return 0;
}we could use,
Code:

int main () { cout << “Hello World!”; return 0; }
In C++, the separation between a statement and another is the semicolon (Wink at the end of each one, so the seperation in different lines doesn’t matter in this purpose. We can write multiple statements per line or write a single one that takes many lines. The division of code only makes it more legible and schematic for anyone that reads it.

Let’s add more to our first program:
Code:

// We’re making more coding! Yay!
#include <iostream>
using namespace std;
int main ()
{
cout << “Hello World! “;
cout << “I’m a C++ program”;
return 0;
}

In our new source, we’ve added a new insertion into cout, in two different statements. The seperation of the lines of code just makes it easier to read, and the source could’ve been perfectly valid this way:

Code:

int main () { cout << ” Hello World! “; cout << ” I’m a C++ program “; return 0; }C++ is made to be convenient. You can also do this.

Code:

int main ()
{
cout <<
“Hello World!”;
cout
<< “I’m a C++ program”;
return 0;
}

They’re read and processed by the preprocessor and don’t produce any code alone. They must be specified in their own line and do not have to end with a semicolon

 

www.extremehacking.org
CEHv9 CHFIv9 ECSAv9 CAST ENSA CCNA CCNA SECURITY MCITP RHCE CHECKPOINT ASA FIREWALL VMWARE CLOUD ANDROID IPHONE NETWORKING HARDWARE TRAINING INSTITUTE IN PUNE,Certified Ethical Hacking, Center For Advanced Security Training in India,IT Security Training Information Security Traning Courses in Pune, ceh certification in pune, Ethical Hacking Course in Pune