2. History
• In 1967 BCPL language was created by Master Martin used to write operating
systems and compilers.
• 2 years later B language was developed by Ken Thomas. UNIX operating system
was developed in B in 1970. It is a type less language. Each data item occupy one
word in memory.
• In 1972 C language was developed by Dennis Ritche. It is the combination of B
and BCPL. New features like data types were also added. UNIX was revised in C.
C language is computer independent language. A program written in C can run on
any computer
• In 1980’s C++ was developed by Bjarne Stroustrup which is the extension of C.
C++ was designed for UNIX system environment. C++ enabled programmers to
improve the quality of code. It includes object oriented programming.
3. C++ Compiler
• C++ compiler translates a C++ source program to machine code.
Machine code is also known as object code.
• It is stored in new files with the extension obj. The object code is then
linked to the libraries. After linking object code to the libraries an
executable file extension exe is created.
• The executable program is then run from operating system command
line.
a.cpp
a.obj
a.exe
4. Structure of C++
1 Preprocessor Directives
2 main ( ) function
3 C++ statements
5. Preprocessor/ Compiler Directives
• The instructions given to the compiler before the beginning of the actual program
are called preprocessor or compiler directives.
• The preprocessor consists of instructions for the compiler.
• Preprocessor directives normally start with a number sign ( # )and the keyword
“include”.
• Preprocessor directives are used to include header files in the program.
# include <iostream.h>
main()
{
Cout << “ This is my first program”;
}
6. Header File
• Header file is a C++ source file that contains definitions of library
functions/objects. Header files are added into the program at the
compilation of the program. A header file is added is added if the
function defined in it is to be used in the program.
• C++ has a large number of header files in which library functions are
defined.
• The header file must be included in the program before calling its
function in the program. A single header file may contain a large
number of built in library functions
# include < name of the header file >
7. main( ) Function
• The main( ) function indicates the beginning of C++ program. main( ) must
be included in every C++ program.
• When a C++ program is executed, the control goes directly to the main( )
function.
• The statements within this function are the main body of the C++ program.
• If main function is not included, the program is not compiled and an error
message is generated.
main ( )
{
Program statements
}
8. C++ Statements
• The statements of the program are written under the main( )
function between curly braces { }. These statements are the
body of the program.
• Each statement in C++ ends with a semicolon (;)
• C++ is a case sensitive language. The C++ statements are
normally written in lower case letters but in some cases these
can also be written in uppercase.
9. Keywords
• The words used by the language for special purposes are
called keywords.
• These are also called reserved words.
• In C++ program, the word main is used to indicate the
starting of the program, include is used to add header files,
int to declare an integer type variable.
• The keywords cannot be used as variable names in a
program.
10. Tokens
• A program statement consists of variable names, keywords, constants,
punctuation marks, operators etc. In C++, these elements of a
statement are called tokens.
• In the following program segment:
main()
{
Int a,b;
}
• main,{,},int,a,b, punctuation marks (,) and (;) are tokens of the
program
11. Variables
• A quantity whose value may change during the execution of the
program is called variable. It is represented by symbol or name.
• A variable represents a storage or memory location in the
computer memory. Data is stored into the memory location.
• The name of the memory location and variable name remains
fixed during execution of the program.
• But data stored in the location may change from time to time.
• A variable is also known as object in C++.
• In C++ a variable name consists of alphabets and digits.
12. Rules of Writing variables
• The first character of a variable name must be an
alphabet character.
• Blank spaces are not allowed in the variable name.
• Special characters such as arithmetic operators #, ^
cannot be used in the variable name.
• A variable name declared for one data type cannot be
used to declare another data type.
13. Data Types in C++
1 Int Integer
2 float Floating Point
3 double Double Precision
4 char Characters
5 bool Boolean
14. Declaration of Variables
• Assigning the name and data type that a variable can hold is called the declaration
of the variable.
• All variables that are used in a program are declared using variable declaration
statement.
• Syntax :
• Type list of variables;
Type = int, float etc
Variables = abc, xyz, s,e etc
Int abc, xyz, d, s;
float b;
char num [15];
15. Initialization of Variables
• When a variable is declared, a memory location is assigned to it.
• The value is assigned at the time of declaration.
• Assigning known value to a variable at the time of its declaration
is called initializing of the variable.
Int a = 110, b = 60, c;
16. Arithmetic Operators
• The arithmetic operators are the symbols that represent
arithmetic operations. These are used in arithmetic expressions.
Each arithmetic operator operates upon two numeric values and
returns a value.
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% For remainder
17. Arithmetic Expression
• An arithmetic expression is a combination of variables, constants
and arithmetic operators.
• It is used to calculate the value of an arithmetic formula.
• The value of the expression is assigned to a variable on the left side
of “=“ operator. This variable is also known as the receiving
variable.
• The operator ”=“ is called the assignment operator. It is used to
assign the calculated value of the expression to the receiving
variable.