You are on page 1of 17

CHAPTER 1 :

INTRODUCTION TO C++

What is C++
C++ is an intermediate level of programming
language which can support to encapsulate both high
and low level language feature.
It can support object oriented programming language.

C++ is an extension of C language

Uses of C++ Language


C++ is used by programmers to create computer
software like system software, drivers, software for
server, software for specific application and used in
creation of video games.

C++ Program Structure


Example 1:
/*
* File: main.cpp
* Author:
*/
#include <iostream>
using namespace std;
int main() {
cout<<"This is my first c++ Program.";
cout<<endl<<"and its very easy";
return 0;
}

Code

Explaination

/* Comments*/

A way of explaining what makes a


program.
Comments are ignored by the compiler
and used by others programmers to
understand the codes.

#include<iostream>

Preprocessor directive.
It tells the preprocessor to include the
contents of iostream header file in the
program before the compilation. This file is
required for input output statements.

Using namespace std;

Required when we used


#include<iostream>.
Contain all the clases, objects and
functions.

int/void

Return value

main()

Main function ehere program execution


begins. Every C++ program should contain
only one main function.

Continue.
Code

Explaination

cout<<

Use for output statement

cin>>

Use to input statement

return 0;

At the end of the main function


return value 0.

; (semicolon)

Always at the end of each statement


to avoid syntax error.

endl;
\n

Create new line by ending the last


statement.

C++ Data Types


Data type (keywords)

Description

char

Any single character (letter digit,


space, punctuation mark).

Int

Integer.

Short

Short integer.

Long

Long integer.

Float

Decimal number

Double

Double precision floating point


number. More accurate than
float.

Rules of Declaring variables in c++

Can consists of
capital letters A-Z
lowercase letters a-z
Digit 0-9
Underscore character

Not allowed
blank space
Special characters (#,$)
C++ keyword cannot be used

First character MUST be a letter or underscore

Variable names are case sensitive.

Example
/* variable definition and initialization */
int width, height=5;
char letter='A';
float age, area;
double d;
/* actual initialization */
width = 10;
age = 26.5;

C++ Constant

Constant are also called literals.

It can be any type of datatype.


#include<iostream>
using namespace std;
int main()
{
const int SIDE = 50;
int area;
area = SIDE*SIDE;
cout<<"The area of the square with side: " << SIDE <<" is: " << area
<< endl;
system("PAUSE");
return 0; }

C++ Storage Classes

Automatic

External

Static

register

Automatic

C++ operators

A symbol that is used to perform mathematical or logical manipulation.

Arithmetic Operators :

Operator

Description

Addition

Subtraction

Multiplication

Division

Modulus

Increment and Decrement Operators


Operator

Description

++

Increment

Decrement

Relational Operators
Operators

Description

==

Is equal to

!=

Is not equal to

>

Greater than

<

Less than

>=

Greater than or equal to

<=

Less than or equal to

Logical Operators
Operato Description
r
&&

AND operator. Performs a logical conjunction on two


expressions.

||

OR operator. Perform a logical disjunction on two


expressions.

NOT operator. Performs logical negation on an


expression.

KEYWORDS

Keyword cant be used as


identifier in C++ programs,
it also called a reserved
words.

Keyword used to perform


internal operation.

TUTORIALS

You might also like