0% found this document useful (0 votes)
64 views17 pages

C++ Introduction

The document introduces C++ by explaining what it is, why it is used, and how to get started with the language. It covers setting up an IDE, writing a simple Hello World program, and basic syntax like comments, output statements, and new lines.

Uploaded by

MAHER MOHAMED
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views17 pages

C++ Introduction

The document introduces C++ by explaining what it is, why it is used, and how to get started with the language. It covers setting up an IDE, writing a simple Hello World program, and basic syntax like comments, output statements, and new lines.

Uploaded by

MAHER MOHAMED
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Welcome

C++
By Eng.Adulahi M. Adan

http://www.mahergelle.com
Chapter One: -
C++ Introductions
C++ Introductions
Contents

 What is C++?
 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, and 2020 to C++11, C++14, C++17, C++20.
Why Use C++
Contents

 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.
C++ Get Started
Contents

 To start using C++, you need two things:


1. A text editor, like Notepad, to write C++ code
2. A compiler, like GCC, to translate the C++ code into a
language that the computer will understand
 There are many text editors and compilers to choose from.
In this course, we will use an IDE (see below).
C++ Install IDE
Contents

 An IDE (Integrated Development Environment) is used to


edit AND compile the code.
 Popular IDE's include Code::Blocks, Eclipse, and Visual
Studio. These are all free, and they can be used to both
edit and debug C++ code.
 Note: Web-based IDE's can work as well, but functionality
is limited.
 We will use Code::Blocks in this course, which we believe
is a good place to start.
Contents
C++ Quick start
Contents

Let's create our first C++ file.


Open Codeblocks and go to File > New > Empty File.
Write the following C++ code and save the file as
firstcode.cpp (File > Save File as):
C++ Quick start
Contents

#include <iostream>
using namespace std;

int main() {
cout << "Hello World!";
return 0;
}
Example explained
Contents

 Line 1: #include <iostream> is a header file library that


lets us work with input and output objects, such
as cout (used in line 5).
 Line 2: using namespace std means that we can use
names for objects and variables from the standard library.
 Line 3: A blank line. C++ ignores white space. But we use
it to make the code more readable.
 Line 4: Another thing that always appear in a C++ pro-
gram, is int main(). This is called a function. Any code
inside its curly brackets {} will be executed.
Example explained
Contents

 Line 5: cout (pronounced "see-out") is an object used together


with the insertion operator (<<) to output/print text. In our example
it will output "Hello World!".
 Note: Every C++ statement ends with a semicolon ;.
 Note: The body of int main() could also been written as:
int main () { cout << "Hello World! "; return 0; }
 Remember: The compiler ignores white spaces. However,
multiple lines makes the code more readable.
 Line 6: return 0 ends the main function.
 Line 7: Do not forget to add the closing curly bracket } to actually
end the main function.
C++ Output
Contents

 C++ Output (Print Text)


 The cout object, together with the << operator, is used to
output values/print text:
 You can add as many cout objects as you want. However,
note that it does not insert a new line at the end of the
output:
 Example
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!";
cout << "I am learning C++"; return 0; }
C++ New Lines
Contents

 To insert a new line, you can use the \n character:


Example
cout << "Hello World! \n";
cout << "Hello World! \n";
cout << "I am learning C++";

 Another way to insert a new line, is with the endl


manipulator:
Example
cout << "Hello World!" << endl;
cout << "Hello World!" << endl;
cout << "Hello World!" ;
C++ Comments
Contents

 Comments can be used to explain C++ code, and to make


it more readable.
 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).
 // This is a comment
 Multi-line comments start with /* and ends with */.
 Any text between /* and */ will be ignored by the compiler:
 /* The code below will print the words Hello World!
to the screen, and it is amazing */
Lesson End
Thank you
@Eng.Abdulahi Mohamed

You might also like