C++
C++
What is C++
• C++ is a general purpose, case-sensitive, free-form programming
language that supports object-oriented programming.
• The language was updated 4 major times in 2011, 2014, 2017, and
2020 to C++11, C++14, C++17, C++20.
Object-Oriented Programming (OOPs)
Inheritance
Polymorphism
Encapsulation
Abstraction
C++ Standard Libraries
• Core Library
• Standard Library
• Standard Template Library (STL
Difference between C and C++
• Both the languages have a similar syntax.
• Code structure of both the languages are same.
• The compilation of both the languages is similar.
• They share the same basic syntax. Nearly all of C’s operators and
keywords are also present in C++ and do the same thing.
• C++ has a slightly extended grammar than C, but the basic grammar
is the same.
• Basic memory model of both is very close to the hardware.
Usage of C++
• Window application
• Client-Server application
• Device drivers
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++ program is int main(). This
is called a function. Any code inside its curly brackets {} will be executed.
Line 7: Do not forget to add the closing curly bracket } to actually end
the main function.
Omitting Namespace
• 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 :: operator for some objects.
C++ Output (Print Text)
New Line
• Another way to insert a new line, is with the \n & endl.
C++ Basic Input and Output (I/O)
C++ Variable
float f=30.8;
char c='A';
Escape Sequence
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).
C++ Multi-line Comments
Multi-line comments start with /* and ends with */.
C++ Variables
Other Types
C++ User Input
Good To Know
cout is pronounced "see-out". Used for output, and uses the insertion
operator (<<)
cin is pronounced "see-in". Used for input, and uses the extraction
operator (>>)
Creating a Simple Calculator
C++ Math
• Max and Min
C++ <cmath> Header
C++ If ... Else
Example
C++ If Example
C++ switch
C++ For Loop
Example
C++ Nested
C++ While loop
C++ Do-While Loop
C++ Nested do-while Loop
C++ Break Statement
C++ Continue Statement
Thank You