Lec 1
Lec 1
Lec 1
PC Based
LECTURE 1
Dr. Sherif Kamal
Course Contents:
• C++ Overview
• C++ Basics
• C++ Variables and Constants
• C++ Data Types and Literals
• C++ Operators
• C++ Input/Output
• C++ Control Statements
• C++ Functions
• Class and Objects
• File Handling
• C++ Pointers and References
• C++ Arrays
• C++ Strings
• C++ Structures and Unions
• C++ Dynamic Memory Management
• C++ Object-Oriented Programming
• C++ Encapsulation and Abstraction
• C++ Function Overloading
• C++ Operator Overloading
Reference Books:
1. “The C++ Programming Language” by Bjarne Stroustrup
2. “Effective C++: 55 Specific Ways to Improve Your Programs
and Designs” by Scott Meyers
3. “C++ Primer Plus” by Stephen Prata
4. “C++ For Dummies” by Stephen R. Davis
5. “Data Structures and Algorithm Analysis in C++” by Mark
Allen Weiss
6. The name of C++ signifies the evolutionary nature of the
changes from C. “++” is the C increment operator.
7. C++ is one of the predominant languages for the
development of all kind of technical and commercial
software.
8. C++ introduces Object-Oriented Programming, not present in
C. Like other things, C++ supports the four primary features
of OOP: encapsulation, polymorphism, abstraction, and
inheritance.
9. C++ got the OOP features from Simula67 Programming
language.
10. A function is a minimum requirement for a C++ program to
run.(at least main() function)
Features of C++
•
C++•• is a general-purpose programming language that was developed as an enhancement of
the C language to include an object-oriented paradigm. It is an imperative and compiled
language. C++ has a number of features, including:
• Object-oriented Programming
• Machine Independent
• Simple
• High-Level Language
• Popular
• Case-sensitive
• Compiler Based
• Dynamic Memory Allocation
• Memory Management
• Multi-threading
1. Object-Oriented Programming
language. This is the most important feature of C++. It can create/destroy objects while
programming. Also, It can create blueprints with which objects can be created. We have
• Class
• Objects
• Encapsulation
• Polymorphism
• Inheritance
• Abstraction
2. Machine Independent
Windows), however, they are machine-independent. Let us understand this feature of C++
with the help of an example. Suppose you have written a piece of code that can run on
Linux/Windows/Mac OSx which makes the C++ Machine Independent but the executable
3. Simple
It is a simple language in the sense that programs can be broken down into logical units and
parts, has rich library support and has a variety of data types. Also, the Auto Keyword of C++
Auto Keyword
The idea of the auto keyword was to form the C++ compiler to deduce the data type while
compiling instead of making you declare the data type every freaking time. Do keep in mind
that you cannot declare something without an initializer. There must be some way for the
4. High-Level Language
makes life easier to work in C++ as it is a high-level language it is closely associated with the
5. Popular
C++ can be the base language for many other programming languages that supports the
feature of object-oriented programming. Bjarne Stroustrup found Simula 67, the first object-
6. Case-sensitive
It is clear that C++ is a case-sensitive programming language. For example, cin is used to take
input from the input stream. But if the “Cin” won’t work. Other languages like HTML and
7. Compiler Based
C++ is a compiler-based language, unlike Python. That is C++ programs used to be compiled
and their executable file is used to run them. C++ is a relatively faster language than Java
and Python.
When the program executes in C++ then the variables are allocated the dynamical heap space.
Inside the functions, the variables are allocated in the stack space. Many times, We are not
aware in advance how much memory is needed to store particular information in a defined
variable and the size of required memory can be determined at run time.
9. Memory Management
• C++ allows us to allocate the memory of a variable or an array in run time. This is
• In other programming languages such as Java and Python, the compiler automatically
manages the memories allocated to variables. But this is not the case in C++.
after it is of no use.
• The allocation and deallocation of the memory can be done using the new and delete
operators respectively.
10. Multi-threading
allows your system to execute two or more programs concurrently. In general, there
program.
• A multithreaded program contains two or more parts that will run concurrently. Each
part of such a program is named a thread, and every thread defines a separate path of
execution.
• C++ doesn’t contain any built-in support for multithreaded applications. Instead, it
return 0;
}
Output
Hello World
2. #include
This is used to import the entity of the std namespace into the
current namespace of the program. The statement using
namespace std is generally considered a bad practice. When we
import a namespace, we are essentially pulling all type definitions
into the current scope.
4. int main() { }
The opening braces ‘{‘ indicates the beginning of the main function
and the closing braces ‘}’ indicates the ending of the main function.
5. cout<<“Hello World”;
6. return 0
Important Points
1. Always include the necessary header files for the smooth
execution of functions. For example, <iostream> must be
included to use std::cin and std::cout.
2. The execution of code begins from the main() function.
3. It is a good practice to use comments in programs for easy
understanding.
4. cout is used to print statements and cin is used to take
inputs.