0% found this document useful (0 votes)
27 views

C++ Chap 5

Uploaded by

Henok Girma
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

C++ Chap 5

Uploaded by

Henok Girma
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

University of Gondar

Institute of Technology
Department of Electrical and Computer Engineering

By: Endalkachew D.
Chapter five
Fundamentals of C++ Programming Language
Mechanics of Creating a Program (C++)
C++ programs typically go through five-phase edits, preprocess, compile, linking,
load:
Editor(edit): accepts the typing of the source code (or header file).
Source file: the file that contains the program you prepared in the editor after you
save it.(.cpp)
Header file: header files such as iostream
The preprocessor: is a program that scans the source code for preprocessor
directives such as include directives.
Compiler(compile): translates the source code to machine language.
The compiler is another program that translates the preprocessed source code into
corresponding machine language instructions, which are stored in a separate file,
called an object file, having a .obj extension.
Phase of C++ program
IDE Tools
You can use any plain-text editor such as Notepad to write the source code. You also
can download a free compiler, which usually includes a preprocessor and linker.
There are several IDE tools to write a C++ program such as Code Blocks, Code
Warrior, Dev C++, Quency … etc.
The Structure of C++ Programs
Hello world program:
// my first program in C++
#include <iostream>
using namespace std;
int main ()// main () is where program execution begins.
{
cout << "Hello World!";
return 0;
}

Output:

Hello World!
Cont.…

This is a comment line.


All the lines beginning with two slash signs (//) are considered comments and do
not have any effect on the behavior of the program.
They can be used by the programmer to include short explanations or
observations within the source itself.
Cont.…

Sentences that begin with a pound sign (#) are directives for the preprocessor.
They are not executable code lines but indications for the compiler.
#include<iostream> tells the compiler's preprocessor to include the iostream
standard header file. Such as input and output standard files.
Cont.…

C++ uses namespaces to organize different names used in programs.


Every name used in the iostream standard library file is part of a namespace called
std.
Consequently, the cout object is called std::cout. The using namespace std;
statement avoids the need for putting std:: before every reference to cout, so we can
just use cout in our code.
Cont.…

This line corresponds to the beginning of the main function declaration.


The main function is the point by where all C++ programs begin their execution.
It is independent of whether it is at the beginning, at the end, or in the middle of the
code - its content is always the first to be executed when a program starts.
Cont.…

This instruction does the most important thing in this program.


cout is the standard output stream in C++
Notice that the sentence ends with a semicolon character (;).
This character signifies the end of the instruction and must be included after every
instruction in any C++ program
Cont.…

The return instruction causes the main () function to finishing


Will be continued
Q??
Thank you!!

07/23/2021 14

You might also like