SlideShare a Scribd company logo
Programing Fundamentals
C++ Programming Basics
Hafiz Ali Ahmed
ali.ahmed@superior.edu.pk
Superior University, Lahore
Explanation:
This program consists of a single
function called main().
Because of the parentheses()
the compiler comes to know that
this is a function not a variable.
The parentheses aren’t always
empty. They’re used to hold
function arguments
(values passed from the calling program to the function).
Line number 2, 3 are not part of the function.
The word int preceding the function name indicates that this particular
function has a return value of type int.
//main.cpp
#include <iostream>
using namespace std;
int main(){
cout << "Welcome to this course";
return 0;
}
1
2
3
4
5
6
7
8
9
The body of a function is surrounded by
braces (sometimes called curly brackets).
Every function must use this pair of braces
around the function body.
A function body can consist of many
statements but this function has only
2 statements
You can put several statements on one line and one statement in over two or
more lines.
//main.cpp
#include <iostream>
using namespace std;
int main(){
cout << "Welcome to this coursen";
return 0;
}
1
2
3
4
5
6
7
8
9
cout
<<"Welcome to this coursen"
;
1
2
3
cout <<"Welcome Studentsn" ; return 0;
1
We don’t recommend these syntax. it’s
nonstandard and hard to read. but it does
compile correctly.
#include is a preprocessor directive, which
must be written on one line.
#include <iostream> tells the compiler to first
include standard C++ library named iostream to our project.
A string constant "Welcome to this coursen" can also be broken into separate
lines if u insert a backslash () at the line break or divide the string into two
separate strings, each surrounded by quotes.
A programs may consists of many functions but the
main() function will be executed first.
//main.cpp
#include <iostream>
using namespace std;
int main(){
cout << "Welcome to this coursen";
return 0;
}
1
2
3
4
5
6
7
8
9
cout
<<"Welcome 
to this 
coursen"
;
cout
<<"Welcome "
"to this "
"coursen"
;
If there is no function called main() in your
program, an error will be reported when you
run the program.
main function may also call other functions.
There are three statements this program
cout << "Welcome to this coursen";
return 0;
The first statement tells the computer to display the quoted phrase.
A semicolon ; signals the end of the statement. If you leave out the
semicolon, the compiler will often signal an error.
//main.cpp
#include <iostream>
using namespace std;
int main(){
cout << "Welcome to this coursen";
return 0;
}
1
2
3
4
5
6
7
8
9
cout <<"Welcome to this coursen";
The identifier cout (pronounced “C out”) is
actually an object. It is predefined in C++ to
correspond to the standard output stream.
A stream is an abstraction that refers to a
flow of data. The standard output stream
normally flows to the screen display although
it can be redirected to other output devices.
The operator << is called the insertion or put to operator. It directs the
contents of the variable on its right to the object on its left.
In our program it directs the string constant "Welcome to this coursen" to
cout, which sends it to the display.
//main.cpp
#include <iostream>
using namespace std;
int main(){
cout << "Welcome to this coursen";
return 0;
}
1
2
3
4
5
6
7
8
9
In C++, operators can be overloaded. That is, they can perform different
activities, depending on the context.
 The phrase in quotation marks, "Welcome to this coursen", is an example of
a string constant.
 A constant, unlike a variable, cannot be given a new value as the program
runs. Its value is set when the program is written, and it retains this value
throughout the program’s existence.
 The 'n' character at the end of the string constant is an example of an escape
sequence. The 'n' causes the next text output to be displayed on a new line.
Line no. 2, 3 and 4 in our program are called
directives.
The first is preprocessor
directive, and the second is a using directive.
Preprocessor Directives
#include <iostream>
This is not a program statement or a part of a function body. It starts with a
number sign (#). It’s called a preprocessor directive.
A preprocessor directive is an instruction to the compiler.
A part of the compiler called the preprocessor deals with these directives
before it begins the real compilation process.
//main.cpp
#include <iostream>
using namespace std;
int main(){
cout << "Welcome to this coursen";
return 0;
}
1
2
3
4
5
6
7
8
9
The preprocessor directive #include tells the compiler to insert another file
into your source file. In effect, the #include directive is replaced by the
contents of the file indicated.
Using an #include directive to insert another file into your source file is similar
to pasting a block of text into a document with your word processor.
#include is only one of many preprocessor directives, all of which can be
identified by the initial # sign.
The type file usually included by #include is called a header file.
In our program the preprocessor directive #include tells the compiler to add
the source file iostream to the main.cpp source file before compiling.
iostream is example of a header file.
Iostream is concerned with basic input/output operations, and contains
declarations that are needed by the cout identifier and the << operator.
Without these declarations, the compiler won’t recognize cout and will think
<< is being used incorrectly.
The newer Standard C++ header files don’t have a file extension, but some
older header files have the extension .H.
A C++ program can be divided into different namespaces. A namespace is a
part of the program in which certain names are recognized; outside of the
namespace they’re unknown.
The directive using namespace std; says that all the program statements that
follow are within the std namespace.
Various program components such as cout are declared within this
namespace. If we didn’t use the using directive, we would need to add the std
name to many program elements. e.g.
std::cout << "Welcome to this coursen";
To avoid adding std:: dozens of times in programs we use the using directive
instead.

More Related Content

PPTX
Introduction to programming
PDF
fundamental of c++ for students of b.tech iii rd year student
PPT
intro to programming languge c++ for computer department
PPTX
POLITEKNIK MALAYSIA
PPTX
Basics Of C++.pptx
PPTX
C++ AND CATEGORIES OF SOFTWARE
PPTX
computer programming omputer programming
Introduction to programming
fundamental of c++ for students of b.tech iii rd year student
intro to programming languge c++ for computer department
POLITEKNIK MALAYSIA
Basics Of C++.pptx
C++ AND CATEGORIES OF SOFTWARE
computer programming omputer programming

Similar to lecture1 pf.pptx (20)

PPTX
Intro to C++
PDF
Chapter 2 - Structure of C++ Program
PPTX
computer ppt group22222222222222222222 (1).pptx
PPTX
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
PPTX
Intro To C++ - Class 3 - Sample Program
PPT
Fp201 unit2 1
PPTX
C++ basics
PDF
PROGRAMMING FUNDAMENTALS BASICS LECTURE 2
PDF
Tutorial basic of c ++lesson 1 eng ver
PPTX
Introduction to c++
PDF
introductiontoc-140704113737-phpapp01.pdf
PPTX
Programming Fundamentals IDE's Lec3.pptx
PPTX
Lecture 1
PPT
pengenalan mengenai computer dan programming
PPTX
Structure of a C++ Program in computer programming .pptx
PPTX
Introduction Of C++
PPTX
Introduction to C++ lecture ************
PPTX
Introduction to cpp language and all the required information relating to it
PPTX
Object oriented programming 11 preprocessor directives and program structure
PDF
A tutorial on C++ Programming
Intro to C++
Chapter 2 - Structure of C++ Program
computer ppt group22222222222222222222 (1).pptx
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 3 - Sample Program
Fp201 unit2 1
C++ basics
PROGRAMMING FUNDAMENTALS BASICS LECTURE 2
Tutorial basic of c ++lesson 1 eng ver
Introduction to c++
introductiontoc-140704113737-phpapp01.pdf
Programming Fundamentals IDE's Lec3.pptx
Lecture 1
pengenalan mengenai computer dan programming
Structure of a C++ Program in computer programming .pptx
Introduction Of C++
Introduction to C++ lecture ************
Introduction to cpp language and all the required information relating to it
Object oriented programming 11 preprocessor directives and program structure
A tutorial on C++ Programming
Ad

Recently uploaded (20)

PPTX
fundraisepro pitch deck elegant and modern
PPTX
Non-Verbal-Communication .mh.pdf_110245_compressed.pptx
PPTX
Tour Presentation Educational Activity.pptx
DOC
学位双硕士UTAS毕业证,墨尔本理工学院毕业证留学硕士毕业证
PPTX
Effective_Handling_Information_Presentation.pptx
PPTX
Introduction to Effective Communication.pptx
PPTX
worship songs, in any order, compilation
DOCX
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
PPTX
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
PDF
Swiggy’s Playbook: UX, Logistics & Monetization
PPTX
2025-08-10 Joseph 02 (shared slides).pptx
PPTX
Emphasizing It's Not The End 08 06 2025.pptx
PPTX
nose tajweed for the arabic alphabets for the responsive
PPTX
Self management and self evaluation presentation
PPTX
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
PDF
oil_refinery_presentation_v1 sllfmfls.pdf
PPTX
Hydrogel Based delivery Cancer Treatment
DOCX
"Project Management: Ultimate Guide to Tools, Techniques, and Strategies (2025)"
PPTX
An Unlikely Response 08 10 2025.pptx
PPTX
_ISO_Presentation_ISO 9001 and 45001.pptx
fundraisepro pitch deck elegant and modern
Non-Verbal-Communication .mh.pdf_110245_compressed.pptx
Tour Presentation Educational Activity.pptx
学位双硕士UTAS毕业证,墨尔本理工学院毕业证留学硕士毕业证
Effective_Handling_Information_Presentation.pptx
Introduction to Effective Communication.pptx
worship songs, in any order, compilation
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
Swiggy’s Playbook: UX, Logistics & Monetization
2025-08-10 Joseph 02 (shared slides).pptx
Emphasizing It's Not The End 08 06 2025.pptx
nose tajweed for the arabic alphabets for the responsive
Self management and self evaluation presentation
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
oil_refinery_presentation_v1 sllfmfls.pdf
Hydrogel Based delivery Cancer Treatment
"Project Management: Ultimate Guide to Tools, Techniques, and Strategies (2025)"
An Unlikely Response 08 10 2025.pptx
_ISO_Presentation_ISO 9001 and 45001.pptx
Ad

lecture1 pf.pptx

  • 1. Programing Fundamentals C++ Programming Basics Hafiz Ali Ahmed ali.ahmed@superior.edu.pk Superior University, Lahore
  • 2. Explanation: This program consists of a single function called main(). Because of the parentheses() the compiler comes to know that this is a function not a variable. The parentheses aren’t always empty. They’re used to hold function arguments (values passed from the calling program to the function). Line number 2, 3 are not part of the function. The word int preceding the function name indicates that this particular function has a return value of type int. //main.cpp #include <iostream> using namespace std; int main(){ cout << "Welcome to this course"; return 0; } 1 2 3 4 5 6 7 8 9
  • 3. The body of a function is surrounded by braces (sometimes called curly brackets). Every function must use this pair of braces around the function body. A function body can consist of many statements but this function has only 2 statements You can put several statements on one line and one statement in over two or more lines. //main.cpp #include <iostream> using namespace std; int main(){ cout << "Welcome to this coursen"; return 0; } 1 2 3 4 5 6 7 8 9 cout <<"Welcome to this coursen" ; 1 2 3 cout <<"Welcome Studentsn" ; return 0; 1
  • 4. We don’t recommend these syntax. it’s nonstandard and hard to read. but it does compile correctly. #include is a preprocessor directive, which must be written on one line. #include <iostream> tells the compiler to first include standard C++ library named iostream to our project. A string constant "Welcome to this coursen" can also be broken into separate lines if u insert a backslash () at the line break or divide the string into two separate strings, each surrounded by quotes. A programs may consists of many functions but the main() function will be executed first. //main.cpp #include <iostream> using namespace std; int main(){ cout << "Welcome to this coursen"; return 0; } 1 2 3 4 5 6 7 8 9 cout <<"Welcome to this coursen" ; cout <<"Welcome " "to this " "coursen" ;
  • 5. If there is no function called main() in your program, an error will be reported when you run the program. main function may also call other functions. There are three statements this program cout << "Welcome to this coursen"; return 0; The first statement tells the computer to display the quoted phrase. A semicolon ; signals the end of the statement. If you leave out the semicolon, the compiler will often signal an error. //main.cpp #include <iostream> using namespace std; int main(){ cout << "Welcome to this coursen"; return 0; } 1 2 3 4 5 6 7 8 9
  • 6. cout <<"Welcome to this coursen"; The identifier cout (pronounced “C out”) is actually an object. It is predefined in C++ to correspond to the standard output stream. A stream is an abstraction that refers to a flow of data. The standard output stream normally flows to the screen display although it can be redirected to other output devices. The operator << is called the insertion or put to operator. It directs the contents of the variable on its right to the object on its left. In our program it directs the string constant "Welcome to this coursen" to cout, which sends it to the display. //main.cpp #include <iostream> using namespace std; int main(){ cout << "Welcome to this coursen"; return 0; } 1 2 3 4 5 6 7 8 9
  • 7. In C++, operators can be overloaded. That is, they can perform different activities, depending on the context.  The phrase in quotation marks, "Welcome to this coursen", is an example of a string constant.  A constant, unlike a variable, cannot be given a new value as the program runs. Its value is set when the program is written, and it retains this value throughout the program’s existence.  The 'n' character at the end of the string constant is an example of an escape sequence. The 'n' causes the next text output to be displayed on a new line.
  • 8. Line no. 2, 3 and 4 in our program are called directives. The first is preprocessor directive, and the second is a using directive. Preprocessor Directives #include <iostream> This is not a program statement or a part of a function body. It starts with a number sign (#). It’s called a preprocessor directive. A preprocessor directive is an instruction to the compiler. A part of the compiler called the preprocessor deals with these directives before it begins the real compilation process. //main.cpp #include <iostream> using namespace std; int main(){ cout << "Welcome to this coursen"; return 0; } 1 2 3 4 5 6 7 8 9
  • 9. The preprocessor directive #include tells the compiler to insert another file into your source file. In effect, the #include directive is replaced by the contents of the file indicated. Using an #include directive to insert another file into your source file is similar to pasting a block of text into a document with your word processor. #include is only one of many preprocessor directives, all of which can be identified by the initial # sign. The type file usually included by #include is called a header file.
  • 10. In our program the preprocessor directive #include tells the compiler to add the source file iostream to the main.cpp source file before compiling. iostream is example of a header file. Iostream is concerned with basic input/output operations, and contains declarations that are needed by the cout identifier and the << operator. Without these declarations, the compiler won’t recognize cout and will think << is being used incorrectly. The newer Standard C++ header files don’t have a file extension, but some older header files have the extension .H.
  • 11. A C++ program can be divided into different namespaces. A namespace is a part of the program in which certain names are recognized; outside of the namespace they’re unknown. The directive using namespace std; says that all the program statements that follow are within the std namespace. Various program components such as cout are declared within this namespace. If we didn’t use the using directive, we would need to add the std name to many program elements. e.g. std::cout << "Welcome to this coursen"; To avoid adding std:: dozens of times in programs we use the using directive instead.