Advanced Data Structure & Algorithm_1_1724990220299
Advanced Data Structure & Algorithm_1_1724990220299
Introduction to C++
1. 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
4. Applications
C++ is used to create computer programs, and is one of the most
used language in game development.
5. C++ Syntax
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!";
return 0;
}
Explanation:
The #include is a preprocessor directive used to include files
in our program. The above code is including the contents of
the iostream file.
#include <iostream> is a header file library that lets us work
with input and output objects, such as cout
This allows us to use cout in our program to print output on
the screen
using namespace std means that we can use names for
objects and variables from the standard library.
6. C++ Statements
A computer program is a list of "instructions" to be "executed"
by a computer.
In a programming language, these programming instructions are
called statements.
Type 2:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << "\n";
return 0;
}
Type 3:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
6.2: horizontal tab
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\t";
cout << "I am learning C++";
return 0;
}
Output: Hello World! I am learning C++
6.3: backslash character
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\\";
cout << "I am learning C++";
return 0;
}
Output: Hello World!\I am learning C++
6.4: double quote character
#include <iostream>
using namespace std;
int main()
{
cout << "I am learning \"C++\"";
return 0;
}
Output: I am learning "C++"
a list of the single character escape codes:
7. Comments
7.1 Single-line Comments
9. Constants
Constants are expressions with a fixed value.
9.1 Literals
Literals are the most obvious kind of constants. They are used to
express particular values within the source code of a program. for
example, when we wrote: a = 5;
The 5 in this piece of code was a literal constant
9.2 Typed constant expressions
Sometimes, it is just convenient to give a name to a constant value:
const double pi = 3.1415926;
const char tab = '\t';
We can then use these names instead of the literals they were defined
to:
#include <iostream>
using namespace std;
int main ()
{
double r=5.0; // radius
double circle;
circle = 2 * pi * r;
cout << circle;
cout << newline;
}
cout << "I am " << age << " years old and my zipcode is " <<
zipcode;