You are on page 1of 22

C++

Introduction

What is C++?
C++ is an object oriented programming
(OOP) language, develop by Bjarne
Stroustrup, and is an extension of C
language.
It is therefore possible to code C++ in a
C style or object-oriented style.
In centain scenarios, it can be coded in
either way and is thus an effective
example of a hybrid language.

The C++
C++ is a general purpose object oriented
programming language.
It is considered to be an intermediate
level language, as it encapsulates both
high and low level language features.
Initially, the language was called C with
classes as it had all properties of C
language with an additional concept of
classes. However, it was renamed to
C++ in 1983.
It is pronounced C-Plus-Plus

First C++ program


//My first program in C++
#include <iostream>
using namespace std;
int main()
{
cout<<Hello World!\n;
system(PAUSE);
return 0;
}

//My first program in C++


The starting two slash signs indicate that
the rest of the line is a comment
inserted by the programmer but which
has no effect on the behavior of the
program
Programmers use comments to include
short explanations about the code or
program.

Types of comment
single-line comments starting with two
slashes (//) the next characters after the
slashes are counter as comments.
Multi-line comments a comments
starting from /* and all the characters
from the lines until the ending */
character.

#include<iostream>
It means to include the iostream in our
program so that we can use the input
and output stream like cout and cin.

Using namespace std


Namespaces allows us to group a set of
global classes, objects and/or functions
under a name.
If you specify using namespace std
then you dont have to put std::
throughout your code.
The program will know to look in the std
library to find the object.

Using namespace std


Without namespace:
std::cout << Hello World!\n;
With namespace
cout << Hello World!\n;

int main()
Initiates the declaration of a function.
A function is a group of code statements
which are given a name.
The function named main is a special
function in all C++ programs, it is the
function called when the program is run.
The execution of all C++ programs begins
with the main function, regardless of
where the function is actually located
within the code.

the { and }
The open brace ({) marks the beginning
of a function definition, and the closing
brace ({) marks the end.
Everything between these braces is the
functions body that defines what
happens when main is called.
All functions use braces to indicate the
beginning and end of their definition

cout<<Hello World!\n;
A kind of statement displaying a string
Hello World in a console window.
cout means it will display anything after
the << sign.

system(PAUSE);

It makes the console window stays open


until you press anything to terminate
the program.

Escape
Sequences

Escape sequences
Escape Sequence
\
\
\?
\\
\0
\a

Description
Single quote
Double quote
Question mark
Backslash
Null character
Audible bell

Escape sequences
Escape Sequence
\b
\f
\n
\r
\t
\v

Description
Backspace
Form feed(new page)
Line feed(new line)
Carriage return
Horizontal tab
Vertical tab

Preprocessor
Directives

Preprocessor Directives
Preprocessor directives, such as #define
and #ifdef, are typically used to make
source programs easy to change and
easy to compile in different execution
environments.
Directives in the source file tell the
preprocessor to perform specific actions.

The preprocessor recognizes the following


directives:
#define

#error

#import

#under

#elif

#if

#include

#using

#else

#ifdef

#line

#endif

#ifndef

#pragma

Standard C+
+ Header
Files

Standard C++ Header


Files
The standard C++ library is a collection of
functions, constants, classes, objects
and templates that extends the C++
language providing basic functionality
perform several tasks, like classes to
interact with the operating system, data
containers, manipulators to operate with
them and algorithms commonly needed.
The declaration of the different elements
provided by the library are split in
several headers that shall be included in
the code in order to have access to its
components:

The preprocessor recognizes the following


directives:
algorithm

complex

exception

list

stack

bitset

csetjmp

fstream

locale

stdexcept

cassert

csignal

functional

map

strstream

cctype

cstdarg

iomanip

memory

streambuf

cstddef

ios

new

string

cfloat

cstdio

iosfwd

numeric

typeinfo

ciso646

cstdlib

iostream

ostream

utility

climits

cstring

istream

queue

valarray

clocale

ctime

iterator

set

vector

cmath

deque

limits

sstream

cerrno