The document introduces programming and the C++ language. It explains that a program is a set of instructions given to a computer in a programming language to perform tasks. High-level languages like C++ were created because computers only understand binary and it is impossible for humans to program in binary. The document then covers the anatomy of a simple "Hello World" C++ program, including main functions, header files, output statements, strings, and terminators. It concludes by explaining how C++ source code is compiled into machine code and executed.
2. WHAT IS A PROGRAM?
âą A program is a set of instructions in a programming
language given to a computer to perform some useful
task.
3. WHY DO WE NEED TO LEARN A
PROGRAMMING LANGUAGE?
âą A computer is just a machine. It cannot do anything till it is told
to do so. Like a fan for example will not start until we switch it
on.
âą So in order to be able to make it work we need to give it specific
instructions.
4. INSTRUCTING THE
COMPUTER IN SIMPLE
LANGUAGE
âą It will not understand.
We have to
communicate with
this machine in the
language it
understands.
Add the numbers 4 and 5
5. WHAT IS HIGH LEVEL LANGUAGE?
âą The computer understands only binary language or machine language
which contains only two digits, 0 and 1.
âą These are 0 (means off) and 1 (means on).
âą It is humanly impossible to communicate all the commands or
instructions using only these two numbers.
âą So high level languages were created. Such languages are
considered high-level because they are closer to human languages and
further from machine languages.
6. C++ PROGRAMMING LANGUAGE
C++ is a high level
programming
language
01
It was created by
Bjarne Stroustrup.
02
It is a versatile,
powerful object
oriented language
03
8. THE PREPROCESSOR
DIRECTIVE
#include <iostream.h>
void main( )
{
cout<< âHello Worldâ;
}
The symbol # is
the Preprocessor
Directive
A preprocessor
directive is a direct
command to the
compiler
To perform an action
Preprocessor
Directive
10. THE IOSTREAM.H
HEADER FILE
# include <iostream.h>
void main( )
{
cout<< âHello Worldâ;
}
The iostream .h header
file stands for Input
Output stream file
which contains
commands and
instructions necessary
to connect our
program to the input
and output streams.
A header file is a file
with
extension .h which
contains C++ function
declarations and
11. THE MAIN()
FUNCTION
# include <iostream.h>
void main( )
{
cout<< âHello Worldâ;
}
Every c++ program
must have a main()
function as the
execution begins here.
In fact main() is the
only self executing
function in c++.
Since it is a function it
must contain a pair of
brackets and must be
preceded by a return
type, void , in this case.
12. THE MAIN() BODY :
BRACES
# include <iostream.h>
void main( )
{
cout<< âHello Worldâ;
}
The body of main()
consists of executable
statements within a
pair of curly braces. { }
Whatever is written in
these braces is the
code that is executed
when the program is
run.
13. THE COUT
STATEMENT
# include <iostream.h>
void main( )
{
cout<< âHello Worldâ;
}
In this case the main()
function consists of a
single executable
statement;
cout<< âHello Worldâ;
cout stands for
console output. It is
actually a command to
display something on
the output console;
the screen in this case.
14. THE INSERTION(<<)
OPERATORS.
# include <iostream.h>
void main( )
{
cout << âHello Worldâ;
}
cout<< âHello Worldâ;
The << symbol are
known as insertion
operators. They are
used to direct the
output to the console
in this case.
15. THE STRING IN
DOUBLE QUOTESâ â
# include <iostream.h>
void main( )
{
cout<< âHello Worldâ;
}
âHello World â is a
constant string. It is
displayed as a
message on the
screen. Any text or
number or symbol
written within a pair of
â â apostrophes is
displayed as it is on
the screen.
16. THE STATEMENT
TERMINATOR(;)
# include <iostream.h>
void main( )
{
cout<< âHello Worldâ ;
}
The semicolon ; is a
statement terminator
in c++. It is used at the
end of various
executable statements
and declarations to
mark the end of a
statement.
17. C++ source code
# include <iostream.h>
void main( )
{
cout<< âHello Worldâ;
}
Hello World
Output
THE EXECUTION OF THE FIRST
PROGRAM
18. HOW THE C++ PROGRAM
IS EXECUTED
Executable code(running the program)
First.exe
Machine language code(compiler)
First.obj
Source code( Create on Editor)
First.cpp
The c++ source code is written on the c++ editor. When
it is saved a file with the extension .cpp is generated
It is then compiled, wherein the compiler converts the
high level program to machine language. A file with the
extension .obj is generated
The machine code is then executed to generate an
executable file. A file with extension .exe is executed.
NOTE : the process of compilation also generates syntax
errors if any.