0% found this document useful (0 votes)
26 views39 pages

C++

C++ notes
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)
26 views39 pages

C++

C++ notes
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/ 39

C++

What is C++
• C++ is a general purpose, case-sensitive, free-form programming
language that supports object-oriented programming.

• C++ is a middle-level language, as it encapsulates both high and low


level language features.

• 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

• Embedded firmware etc


C++ Syntax
Syntax explained

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). Header
files add functionality to C++ programs.

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 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.
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

int x=5,b=10; //declaring 2 variable of integer type

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

You might also like