L2 - INTRODUCTION TO C++ PROGRAMING
L2 - INTRODUCTION TO C++ PROGRAMING
By Sir. Joshua
Definition
C++ is a cross-platform language that can be
used to create high-performance applications.
C++ was developed by Bjarne Stroustrup,
as an extension to the C language.
C++ gives programmers a high level of control
over system resources and memory.
The
language was updated 4 major times in
2011, 2014, 2017 , 2020 , and 2023 to C++11,
C++14, C++17, C++20 and C++23.
Why Use C++?
C++ is one of the world's most popular programming
languages.
C++ can be found in today's operating systems,
Graphical User Interfaces, and embedded systems.
C++ is an object-oriented programming language
which gives a clear structure to programs and allows
code to be reused, lowering development costs.
C++ is portable and can be used to develop
applications that can be adapted to multiple
platforms.
C++ is fun and easy to learn!
As C++ is close to C, C# and Java, it makes it easy for
programmers to switch to C++ or vice versa.
History of C++
History of C++ language is interesting to know.
Here we are going to discuss brief history of C++ language.
C++ programming language was developed in 1980 by
Bjarne Stroustrup at bell laboratories of AT&T (American
Telephone & Telegraph), located in U.S.A. Bjarne
Stroustrup is known as the founder of C++ language.
It was develop for adding a feature of OOP (Object
Oriented Programming) in C without significantly
changing the C component.
C++ programming is "relative" (called a superset) of C, it
means any valid C program is also a valid C++ program.
Programming languages that were
developed before C++ language
2) Data is less secured in C. In C++, you can use modifiers for class members
to make it inaccessible for outside users.
7) In C, scanf() and printf() are C++ mainly uses stream cin and cout to
mainly used for input/output. perform
10) C does not provide the feature C++ supports the feature of namespace.
of namespace.
11) Exception handling is not easy C++ provides exception handling using
in C. It has to perform using Try and
other functions. Catch block.
NOTE
Every C++ statement ends with a semicolon (;).
The body of int main() could also been written as:
int main () { cout << "Hello World! "; return
0; }
The compiler ignores white spaces. However, multiple
lines makes the code more readable.
Omitting Namespace
You might see some
C++ programs that
runs without the
standard
namespace
library.
• The using
namespace std line
can be omitted and
replaced with the
std keyword,
followed by the ::
C++ Statements
A computer program is a list of “instructions” to be
“executed” by a computer.
These instructions are called “statements”.
Every C++ statement ends with a semicolon (;), if
you forget the semicolon an error will occur and the
program will not run.
cout << “Hello World”;
For example:
Instructs a computer to print the text “Hello World”
Most C++ programs contain many statements, these
statements are executed one by one in the same order
as they are written.
Environment setup for C++
program
To start using C++, you need two things:
a) A text editor, like Notepad, to write C++ code
b) A compiler, like GCC, to translate the C++ code
into a language that the computer will understand.
An IDE (Integrated Development Environment) is
used to edit AND compile the code.
Popular IDE's include Code::Blocks, Eclipse, Dev
C++ (. Embarcadero DEV C++) and Visual
Studio. These are all free, and they can be used to
both edit and debug C++ code.
Writing of C++ program in the
content pane of the compiler
Saving a C++ program
Running
a program involves copying a
program to the RAM.
Themessage is sent to the computerto
prepare the environment for operating a
program.
Runyour C++ program by clicking the
Execute” tab, then click “Run.”
…
Comments in C++ program
(Documentation)
Comments can be used to explain C++
code, and to make it more readable.
It
can also be used to prevent execution
when testing alternative code.
Comments can be singled-lined or multi-
lined.
Single-line Comments
Single-line comments start with two forward
slashes (//).
Any text between // and the end of the line is
ignored by the compiler (will not be executed).
These are examples of single-line comments:
Multi-line Comments