Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: C++ Programming Language Notes
Description: C++ is a general-purpose, object-oriented programming language. It was created by Bjarne Stroustrup at Bell Labs circa 1980. C++ is very similar to C (invented by Dennis Ritchie in the early 1970s). This C++ course is a beginner-friendly course that can help you grasp coding concepts even if you are an absolute beginner.

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


Introduction to C++ Programming
C++ is a general-purpose, object-oriented programming language
...
C++ is
very similar to C (invented by Dennis Ritchie in the early 1970s)
...
It is often
taught in colleges after C programming and before Java
because it is considered an object-oriented programming
language
...

Course Outline








Basics of the language
Differences between object-oriented, procedural
oriented, and functional programming
Differences between C++ and C language
Main features of C++ and how to write over the C
language
Object-oriented programming concepts and how to
write programs using them



Access specifiers and object classes



Practical examples and real-life scenarios



Use of Standard Template Library



The history of programming and the history of C++
programming language

C++ Programming Language
C++ is an object-oriented programming language that follows the
concepts of OOP
...

Theory and Practical Aspects of Programming
This video will demonstrate how to learn the theory and practical
aspects of programming in C++
...
In this video, we will discuss both the
theoretical concepts and practical aspects of the language
...
The series aims to
teach object-oriented programming, and the previous episode provides
a guide to the first chapter of this episode
...

Procedural Programming Paradigm
Procedural programming is divided into parts that are known as
procedures or functions
...
Procedural programming paradigms focus on the
algorithm, how to do the task rather than the data, whereas in objectoriented programming, we focus more on the data than how the task is
done
...
Scalability is also not there, and security is not a
strong point
...

Creating Software
We are creating software like a hospital management system, library
management system, shopping cart, and some e-commerce websites

like Amazon and Flipkart
...
" We will also talk about how it is
possible to create software that can be used to run a hospital or a
computer in the future
...
It will be a virtual reality-based software that would be used for
the first time in the next time
...
We are designed to have a physical environment, and we would
have virtual space or physical space
...


Object Oriented Programming (OOP) vs Processor
Oriented Programming (POP)
Processor oriented programming is not suitable for complex and large
scale applications due to data security concerns
...
Each object has its own attributes
(height, color, weight, etc
...
This increases productivity and
eliminates the need to repeat code
...
Without them, a
program cannot be written
...
OOP
is designed to communicate through message passing and provide
secure data for the application user
...


Let's take the example of a student to understand the concept of a
class
...

The class defines the core properties and functions of the entity, such as
height, weight, and the ability to eat, sleep, and study
...

Each object has its own data and functions, and objects can interact
with each other without the need for internal knowledge of each other's
data and code
...

Understanding OOP Concepts: Class, Inheritance, Abstraction, and
Encapsulation
In Object-Oriented Programming (OOP), classes serve as a blueprint for
creating objects
...
Inheritance is a way to reuse code by allowing
child classes to inherit properties and functions from a parent or base
class
...



Child/Derived class: Inherits properties from a parent/base class



Base/Parent class: Contains common properties and functions
that can be inherited by child classes

Abstraction is the process of hiding implementation details from the
user and only showcasing relevant details
...
Encapsulation involves binding data and
functions together in one unit
...


Why Do We Need a Programming Language?
To communicate with our computers and give instructions to our
systems, we need a programming language
...

Therefore, we need a programming language to convert our
instructions into machine code that computers can understand
...
It was
developed by Bjarne Stroustrup in 1983 as an extension of the C
language
...

History of C++
Bjarne Stroustrup, a Danish computer scientist, developed C++ in 1979
as an extension of the C language
...
Stroustrup wanted to create a language that
was fast and efficient, like C, but also supported OOP concepts
...
The latest version of C++ is C++20, which was
released in 2020
...




It supports both procedural and object-oriented programming
paradigms
...




It is a middle-level language, meaning it supports both lowlevel and high-level programming
...


Introduction to C++ Language:
In this video, we will introduce you to the C++ language
...
It is an extension of the C programming language and is used
to develop software applications, operating systems, video games, and
much more
...
The next revision, C++23, is
expected to be released in 2023
...



C++ is an object-oriented programming language that supports
OOPS concepts such as object abstraction, encapsulation,
polymorphism, and inheritance
...
It is a
general-purpose programming language that can be used to
create software and applications in any domain
...




C++ is considered a faster language than other programming
languages because it doesn't have automatic garbage collection
and is compiled directly into machine code
...




C++ is portable, meaning that a program written on one
machine can be run on another machine with the same
operating system
...
Its features make it a popular language for creating a wide
range of applications in various domains
...
It is also portable, but platform-dependent,
meaning it requires the same operating system to run
...
C++
is a strongly-typed programming language, requiring the declaration of
variables before use
...
The
executable file created here can only be run on a machine with the
same operating system
...
The
language is extensible, allowing users to add their own user-defined
functions to the existing library
...


Case Sensitivity
C++ is a case-sensitive language, meaning it considers lowercase and
uppercase letters as different
...

Pointers
C++ supports the concept of pointers, allowing users to interact directly
with memory locations and manipulate low-level memory
...


History of C++
C++ was developed by Bjarne Stroustrup, a computer scientist at AT&T
Bell Laboratories, in 1979
...

He thought that the concepts of Object-Oriented Programming (OOPs)
would be very beneficial to develop large software
...
Basic features like classes,
basic inheritance, single inheritance concept, default function argument
concept, inlining polymorphism, etc
...
The
first C with classes compiler was also released, known as Cfront, derived
from the Compass C compiler
...
However, the use of this compiler
was abandoned in 1993 because it became difficult to add new features

to integrate new features into it
...



C with Classes (1979)



C++ 1
...
0 (1989)



C++ 98 (1998)



C++ 03 (2003)



C++ 11 (2011)



C++ 14 (2014)



C++ 17 (2017)

C++ was implemented as a commercial product in 1985, and the first
commercial version was released in the same year
...
The Standard Template Library (STL) was also included in this
version
...
In 2005, the same committee released a
technical report in which various new features that they were planning
to add in the latest version of the C++ were mentioned
...
Many new
features were added like auto keyword, new libraries, regular expression
support, lambda expressions, etc
...
Finally, in 2017, another major release was there with the addition
of new features and great changes in this version, known as C++ 17
...
The live
weekend classroom program is designed for people who wish to excel
in competitive programming and SD interviews
...
In this course, you will be mentored by industry
experts, and it also includes DSA course quizzes, more contests, and

much more
...
The registration link and all the relevant details are in the
description box of this video
...
Many new header files and libraries were
added, and some obsolete features were removed
...

New features were added, such as the threeway comparison operator
...


Understanding Name Spaces in C++ Programming
In C++ programming, name spaces are used to resolve conflicts
that arise due to the use of the same name for multiple objects,
functions, or classes
...













To create a name space, use the keyword "namespace"
followed by the name of the name space
...

The scope resolution operator is used to indicate which
name space an object, function, or class belongs to
...

The main function is compulsory and is where the
execution of the program begins
...


Constants
Constants are fixed values that cannot be changed during the execution
of a program
...
Integer constants are simple numbers,
while real or floating point constants have a decimal point
...
Invalid
constants include special symbols and spaces
...
We
name these memory locations because we need a way to access and
modify them
...
We declare variables using data
types, such as int for integers, and const keyword, to define constants
...
However, once we define a constant, we cannot modify it during
the execution of the program
...


Understanding Variables and Constants in C++
In C++, variables are used to store data in memory location and are
named accordingly
...
On the other hand, constants are
also used to store values in memory, but their value cannot be modified
during program execution
...




Variables are defined using the syntax: datatype
variable_name=value; while constants are defined using
the syntax: #define constant_name value or const
datatype constant_name=value;
...
Using the #define macro before the name of the constant
...
Using the const keyword before the datatype of the constant
...
The syntax for defining a constant using
the #define macro is: #define constant_name value , while
the syntax for defining a constant using the const keyword
is: const datatype constant_name=value;
...
Special
characters are not allowed
...

Example Program
Here is an example program that demonstrates the use of variables and
constants in C++:
#include
using namespace std;
int main() {
const int a = 89;
cout << a << endl;

a = 78;
cout << a << endl;
return 0;
}

Keywords and Identifiers in C++
In this video, we will discuss keywords and identifiers in C++
...
Keywords and identifiers are the building blocks
of a program, and we will explore their significance and some
interesting facts about them
...
It can be the name of a variable, function, class, object,
namespace, macros, etc
...
It must begin with a letter or underscore
and can only contain letters, digits, and underscores
...
C++ does not impose any limit on the length
of an identifier, but the first 31 characters are considered significant
...
They are written in small letters and cannot be used as
identifiers
...
Some keywords have alternative forms that represent
the same operators, such as and, or, not, etc
...
They can be used as identifiers in a program,
such as main, std, endl, etc
...
The program
prints the value of a, which is 10
...

Here is a list of predefined identifiers:


cout



main



iostream



cin

You can use these as variable names or for creating new functions
...
For example, if you use "cout" as a variable name and
then try to use "cout" from the "std" namespace, it will cause an error
...

When using the "std" namespace, it is a good practice to explicitly write
"std::cout" instead of using "using namespace std" to avoid any
conflicts
...


Data Types in C++ Programming Language
In the previous video, we discussed keywords and identifiers in C++
programming language
...
We will cover what is a data type, why
we need it, and the different types of data types
...

Built-in Data Types in C++
There are two types of data types: primary (built-in) and user-defined
...

There are eight primary data types:


int



float



double



char



wchar_t



bool



void

We will discuss each of these data types with examples in this video
...
We need to
tell the computer how much memory we need to store a particular
piece of information
...
Data types tell us what
type of data we want to store and how much memory we need to
allocate for it
...
If we want to store a phone
number, we need to allocate more memory
...
Data types help us
allocate the appropriate amount of memory for the data we want to
store
...
The required
experience is 0-3 years, and the salary is 6-12 LPA
...


Primary Data Types and Modifiers
Primary data types include arrays, integers, floating points, characters,
pointers, functions, references, user-defined classes, structures, unions,
and enums
...
This
discussion will focus on primary data types and their modifiers
...
It can take two bytes on a 16-bit machine
...



Signed int can store negative, positive, and zero values
...
The range for signed int is -2^31
to 2^31-1
...
The range for
unsigned int is 0 to 2^32-1
...
It takes two bytes
and can be signed or unsigned
...




Long int takes four bytes and can be signed or unsigned
...


Using Modifiers for Memory Efficiency
Using the appropriate data modifier can help optimize memory usage
...

For larger values like phone numbers, using long long int can provide a
larger range than int and long int
...


Float Data Type
Float data type is used to represent single precision decimal or floating
point numbers with a size of 4 bytes
...
Otherwise, the compiler
will assume it is a double data type
...

The default precision for c-out is 6 digits
...
If we need
to print a larger number with more precision, we should use the double
data type, which has a size of 8 bytes and a precision of up to 15 digits
...
However, it is important to note that the precision
beyond the allowed limit may result in garbage values
...
These data
types are used to store decimal and exponential numbers
...
20e+4, it would be written as 1
...

Internally, floating point numbers are stored in a system that is
completely different from integer numbers
...
What you do need to know is the fixed range for float
and double, which is:


For float: -3
...
4e+38



For double: 1
...
7e+308

Be aware that the precision of C++'s cout function is limited to six digits
by default
...

However, you can set the precision value using the setprecision function
from the iomanip header file
...
If you set it to 9, it will print up to
nine digits
...


Character Data Type in C++
In this video, we'll discuss character data type in C++
...
But before we dive into that, let me ask you a question:
Are you preparing for placements? If so, then one subject that is really
important for interview point of view is data structure and algorithm
...
But where can
you find practice problems on these topics? One platform you can use
is GeeksforGeeks
...
You
can even prepare for specific company-wise interview problems
...

What is Character Data Type?
The character data type takes one byte of memory, which means eight
bits to store
...
The maximum and minimum numbers that can be stored
in this data type are 0 and 255, respectively, for unsigned character, and
-128 to 127 for signed character
...
To represent characters in binary, we use character systems
like American Standard Code for Information Interchange (ASCII) table

or Unicode table
...
The ASCII
table has 128 characters and the first 32 are unprintable commands
...
For signed character, the
values range from -128 to 127, while for unsigned character, the values
range from 0 to 255
...
Since the number of characters and symbols in Unicode table
is more than 255, another data type is used to represent them
...
This data type uses 16 bits to represent these
characters, which means that it can represent up to 2 16 - 1 (65,535)
characters
...


Wide Character Data Type
In the previous video, we discussed the character type in C++
...
This data type is used to represent international
languages that have different characters and symbols that cannot be
represented using the cad type
...
For example, "l' a'"
...
The range of this stereotype can
be up to 65535 characters or symbols
...
It is used to
represent all languages from all over the world
...
0 has almost
159 scripts encoded, with 20 new emojis added
...
0 will be
released in September 2022
...
The contest is for candidates looking for fresher
or intern job opportunities
...
There are coding
questions in C++, Java, and Python, as well as MCQs for programming
logic, quantitative aptitude, and logical reasoning
...


Understanding Wide Character Type and Unicode
Encoding
Wide Character type in C++ is used to deal with international languages
and can store characters that regular characters cannot
...
Unicode numbers can be expressed in decimal or
Unicode encoding, which uses the format 'u+xxxx'
...
We then print the character using wcout
instead of cout since it is a wide character
...

#include
using namespace std;
int main()
{
wchar_t ch = L'a';
wcout << ch;
cout<<"Size of wchar_t: " << sizeof(wchar_t);

return 0;
}
If we want to print the decimal value of a Unicode character, we can use
type casting and the 'int' keyword
...
We can
copy and paste the symbol into our program and use type casting to
print its decimal value
...
In this case, the symbol will still be stored in
memory, but will not be displayed properly on the console
...
We will cover everything about these data types,
including what they are, how to use them, and when to use them
...

What is Bool?
Bool is a boolean value that can take two values, either true or false
...
We use this data
type in conditional statements to check if two variables are present
...
For example, if x is greater than y, we can simply write true
rather than 1
...
For example, "bool a = true" will implicitly convert true into 1,
so a will contain 1
...
For instance,
"z = x + y + true - false" is the same as "z = x + y + 1 - 0"
...
We use this data type as
a return type of a function that does not return anything
...

Uses of Void
Another use of void is to create a void pointer, which is a generic
pointer that can be typecasted according to our requirement
...
For example, "void* ptr" is a void pointer that can
contain the address of any variable
...
They have 35 campuses in
30 cities and offer advanced certification in in-demand skills like
blockchain, artificial intelligence, machine learning, data science, big
data, data analytics, and more
...
Students can avail of a scholarship worth Rs
...

In C++, the void data type is used to indicate no type
...

However, you cannot declare a variable of type void
...
It
can also be used in conditional statements and expressions
...
It can also be used as the parameter list when
there are no parameters
...
These are predefined objects
of the i stream and o stream classes
...

Input and Output Streams

The i stream and o stream classes are used to represent input
and output streams in C++
...
g
...
g
...

Insertion and Extraction Operators

The insertion and extraction operators ( << and >>> ) are used with
the cout and cin objects, respectively
...

Example Program

Here is an example program that asks the user for an integer value and
prints it to the screen:
#include using namespace std;int main() {
int a;
>> a;

cout << "Enter an integer value: ";
cout << "You entered: " << a << endl;

return 0;}

cin

In this program, we declare an integer variable a and use
the cin object to read an integer value from the user
...


Using Namespace std
In this file, we are using namespace std
...

Whatever is defined in the iostream is within the namespace std
...
The c out and c in objects are
defined in this header file within the namespace std
...
This is to
avoid confusion between user-defined variables and predefined objects
...
Whenever you execute
the program, control will go to the main function
...
We are printing the string
'Enter a' using the c out object
...
When the user enters a value, it
will be stored in the 'a' variable
...
To fetch the value, we write 'a' again
...
We also use the c in object to
take input from the user
...

Unary operators need only one operand, binary operators work on two
operands, and ternary operators require three operands
...
The increment and decrement operators are also considered
as arithmetic operators
...
For example, 10 % 3 would return 1
...
There are two types of these operators pre-increment/decrement and post-increment/decrement
...
Preincrement/decrement modifies the value of the operand before it is
used, whereas post-increment/decrement modifies the value of the
operand after it is used
...
Relational operators are used to
show the relationship between operands, such as double equal to, not
equal to, less than, greater than, less than or equal to, and greater than
or equal to
...
There are three logical operators: logical
AND (&&), logical OR (||), and logical NOT (!)
...

Logical OR: returns true if either one or both operands
are true
...


Let's take an example to better understand logical operators
...
The operands for logical
operators should be of boolean type
...
The truth table for logical OR is:
Operand 1 Operand 2 Result
0
0
0
0
1
1
1
0
1
1
1
1
The logical NOT operator returns true if the operand is false and
vice versa
...
This saves time and resources
...
There are several bitwise operators:


Bitwise AND (&)



Bitwise OR (|)



Bitwise XOR (^)



Bitwise NOT (~)



Left shift (<<)



Right shift (>>)

Let's take an example to better understand bitwise operators:
Here are some examples of logical and bitwise operators:


If x is 26 and y is 9:


x and y would be 8



x or y would be 27



x xor y would be 19



x left shift 1 would be 52



x right shift 1 would be 13







bitwise not x would be -27 (due to two's
complement)

You can try these operators with different operands,
such as constants or variables
...


Operators in C++
In this series of learning C++ programming language, we have already
discussed arithmetic, relational, bitwise, and logical operators
...

Assignment Operators
The assignment operator assigns the value of the right-hand side to the
left-hand side
...
You can also use combination operators like "+=", "-=", "*=", "/=",
and "%=" to perform arithmetic operations and assign the result to the
left-hand side variable
...
It is represented by the "?" and ":" symbols, and
its syntax is "condition ? expression1 : expression2"
...

Size Of Operator
The size of operator is used to find out the size of a data type or a
variable
...

Address Of Operator
The address of operator is used to get the memory address of a
variable
...
For example, "ptr = &a"
assigns the memory address of variable "a" to the pointer variable "ptr"
...

Cast Operator

The cast operator is used to forcefully convert one data type to another
data type
...


Operators and Type Casting in C++
C++ has various types of operators such as arithmetic, relational,
logical, bitwise, and assignment operators
...

Cast Operator
To use the cast operator, write the data type you want to convert to in
parentheses followed by the variable you want to convert
...

There are two types of casting: implicit and explicit
...

Miscellaneous and Assignment Operators
Aside from the cast operator, there are also miscellaneous operators
such as the conditional operator and assignment operators such
as = , += , and -=
...
The next
important topic is operator precedence and associativity
...
This topic is crucial for solving expressions that involve

multiple operators such as plus, minus, divide, left shift, right shift,
logical and, and logical or
...

What is Operator Precedence?
Operator precedence refers to the priority given to operators to execute
in a particular order
...
For example, consider
an expression like "a = 2 + 3 * 5"
...
Which operator should be executed first?
The answer is based on operator precedence
...

What is Associativity?
Associativity refers to the order in which operators of the same
precedence are executed
...
For example, in an expression like "a + b + c", the
operators are executed from left to right
...

Let's look at an example to understand this better
...
In this expression, we have multiple
operators with the same precedence
...
However, the operators '*' and '/' have the same precedence, so we
need to consider their associativity
...
So, the expression is
evaluated as follows:
2 + ((3 * 5) / 2) % 3 = 2 + (15 / 2) % 3 = 2 + 7 % 3 = 3
By understanding operator precedence and associativity, you can solve
complex expressions with ease
...

Register for the event for free and get access to the calendar of events
and activities
...

Participate and get a chance to win rewards
...
Fill the Google form to

get the cheat code sheet instantly
...
The content
will be available on the website for a few days only, so make sure to
check it out every day
...
For example, for the expression "plus d c
plus d then left shift d and minus 2," we would first add "d" and "c,"
then add the result to "d," shift the result to the left, and finally subtract
2
...
Therefore, the same expression may yield different
results on different machines
...

Example
Let's take an example:
x = 3; y = x+++++x;
Here, we have postfix and prefix increment operators and an arithmetic
plus operator
...
The expression will be
evaluated as follows:


The original value of x (3) is used in the expression
...




The prefix increment operator is executed, incrementing x to 5
...




y becomes 8, and x becomes 5
...
Precedence
refers to the order in which operators are evaluated in an expression,
while associativity refers to the order in which operators of the same
precedence are evaluated
...

Example 1
Let's take the expression x++ + y++
...
Postfix operators have a higher precedence and
left-to-right associativity, while prefix operators have right-to-left
associativity
...
However,
it's important to note that since we're modifying and accessing the
same variable in the same expression, the outcome may be undefined
and can vary depending on the compiler
...
This expression has
brackets, which have the highest precedence
...
So, the expression would be evaluated as
follows:


y-- - post decrement operator is used, original value of y (3)
is used, then y becomes 2



y = 10 - assignment operator assigns 10 to y

So, the output would be 12
...
This demonstrates the
importance of understanding the order of evaluation in expressions in
C++
...
This can
lead to undefined behavior, and the outcome can vary depending on
the compiler
...

Assignment
Validate the following expressions and compare the output on different
machines:


++x * y--



(y = y + 5, x = x + 5, y - x)



x++ * y++ - x-- + y--



x = x + y, y = x - y, x = x - y



y = --x + x++

Sequential Control Structures

Sequential control structures execute statements one by one in
the order in which they appear
...

Selection Control Structures

Selection control structures are used to select specific statements to
execute based on some conditions
...




If-else statement: Executes a block of statements if a condition
is true, and another block of statements if the condition is false
...




Switch statement: Executes a block of statements based on the
value of a variable
...
There are three types of iteration
statements in C++:


For loop: Executes a block of statements a specific number of
times
...




Do-while loop: Executes a block of statements at least once,
and then continues to execute as long as a condition is true
...
It has a general syntax:
if (condition) { statement(s); }
The statements inside the curly braces will only be executed if the
condition is true
...
";

}

} else
return 0;

In the above example, the if statement checks if the person has more
than 1000 rupees
...
If the condition is false, the program will
print "Let's go home
...

If you want to check for equality in the condition, you must use the
double equal sign ( == ) instead of the single equal sign ( = ) which is
the assignment operator
...


Control Structures in C++: If-Else Statements
In this video, we will discuss if-else statements as part of the series on
learning the C++ programming language
...
If-else statements allow for
dual selection, where there are two choices and different statements are
executed depending on which choice is selected
...
The
condition must evaluate to a boolean value (true or false)
...
If the condition is false, the statements
within the else block are executed and the if block is skipped
...

Here is a flowchart to demonstrate the working of if-else statements:

Example Program
Let's take the example of deciding where to have coffee based on the
amount of money you have
...
The program would
look like this:
if (money >= 1000) {
cout << "You have " << money
<< " rupees
...
" << endl;
} else {

cout << "You have " << money << " rupees
...
"
<< endl;
}
cout << "Let's go home
...
Coffee in CCD
...
" If the amount of money is greater than or equal to 1000, the if
block is executed and the program outputs "You have [money] rupees
...
Let's go home
...
They offer courses in programming languages,
machine learning, data science, web development, and more
...

They also offer one-to-one doubt resolution support and practice
problems from top companies like Google, Amazon, and Microsoft
...


If-Else Statements in C++
The if-else statement is a conditional statement that executes a block of
code if a condition is true, and another block of code if the condition is
false
...
" << endl;
}
else{
cout << "Money I have: " << money << endl;
cout << "Let's have coffee in CCD
...
" << endl;
If the amount of money entered by the user is greater than or equal to
1000, the program will output "Money I have: {money}" and "Let's have
coffee in Starbucks
...
"
One can also add semicolons after the if statement or the else
statement
...
If a semicolon is added after the else
statement, the program will not give an error, but the else statement
will be skipped
...

However, if only one statement is written after the if statement, it will be
considered as part of the else block
...
If both conditions are true, the
program should output "Let's have coffee in Starbucks
...
"

Control Structures in C++: Else-If Ladder

In this series on learning C++ programming language, we are
discussing control structures in C++
...
The third control structure is the else-if
ladder
...
We will also
demonstrate the control structure with the help of a program
...
The syllabus, books, and previous year question papers
play a vital role in your GATE preparation
...
You can find the
link to buy the book in the description box of this video
...
If you have only one
choice, you can use the if statement
...
But if you have multiple choices, like buying
vegetables in a supermarket, you can use the else-if ladder
...
If a condition is true, the corresponding
statement will be executed, and the remaining conditions and
statements will be skipped
...


Nested If and Nested If Else in C++
In this series of learning C++ programming language, we are discussing
control structures in C++
...
Now, the next is nested if and nested ifelse
...
In this
video, we will be discussing everything about these statements with the
help of a program and real-life examples
...
If you take this online exam, you will get admission
to one of the best Gate live batches with amazing discounts
...
The top three rankers will get 30%
scholarship, 4 to 10 rankers will get 20% scholarship, and 11 to 50
rankers will get 10% scholarship
...
We can nest if and if-else statements
...
The condition can be nested up to any level, and it is not
limited
...
To enter the inner if, the outer if
condition must be true
...

We can nest if statements up to any level
...
For this
condition to be true, the outer if condition must be true
...

What is Nested If Else?
Nested if-else is something like nested if
...
We use these statements
when we have multiple conditions that are dependent on each other
...
We can nest the conditions up to any level
...


Program for Nested If Condition
Consider the scenario where we have nested conditions
...
If yes, we can have wine, else we can have coffee at
Starbucks
...
Finally, we
need to leave
...
So, the program will have an additional factor to check
...
We will take two variables, money
and partner age
...
If the amount is greater than or equal to 1000 rupees, we will
ask the user to enter the partner's age
...
If the amount is between 500 and
1000 rupees, we can have coffee at CCD, else we can have coffee at a
normal shop
...

#include using namespace std;int main() {
int money, partner_age;
cin >> money;

cout << "Enter money: ";

if (money >= 1000) {

cout <<

"Enter partner age: ";

cin >> partner_age;

(partner_age > 21) {

cout << "Let's have wine

in Starbucks
...
" << endl;
else {

if (money > 500) {

have coffee in CCD
...
" << endl;
}

}

cout << "Let's go home
...
If we have 1200 rupees
and our partner's age is 20, we will have coffee in Starbucks and then
leave
...


If we have 100 rupees, we will have coffee in a normal shop and then
leave
...
For example, if we go to the
supermarket and both apples and oranges are available, we can buy
them
...

Instead of using nested if, we can write a program using logical and
operator
...


Control Structures in C++: Switch Case Statement
In this video, we will be discussing the switch case statement, which is a
substitute for long if-else statements
...
We will cover
what the switch case statement is, why we use it, how to use it with a
program, important points, and some examples
...




Only integral types are allowed in the switch expression, such as
a constant value, variable, or character
...




The break statement is used to terminate the switch and exit
the statement
...
During
these three days, you can get a flat 15% sitewide discount on the entire

website of our services
...

Be sure to mark your calendars and participate in the event!
Switch Case Statement Syntax
The general syntax for writing a switch case statement is:
switch(expression) {
break;

case value 1: statement 1;

case value 2: statement 2; break;

value n: statement n; break;


...

The default statement is optional and executed when no case value
matches the expression value
...
Each case represents a different
possible value of the variable, and the code block associated with that
case will be executed if the variable matches that value
...




The default case is optional, and will be executed if none of the
other cases match
...




If the break statement is omitted, execution will continue into
the next case regardless of whether the value matches or not
...

The switch statement checks the value of the choice variable and
executes the corresponding code block
...
The break statement is used after each case to
exit the switch statement
...
They are used when you need
to execute a statement or a group of statements repeatedly
...
However, this
would be time-consuming and inefficient
...

Types of Loops
There are two basic categories of loops in C++:


For loop: This loop is used when you know the number of
times you want to execute a statement or a group of
statements
...
The loop continues as long as the condition
specified is true
...
They save time, reduce the lines of code, and make the
program more readable and maintainable
...

Loops are used when you want to execute a statement or group of
statements multiple times
...
In programming, we use variables
for updating and checking, unlike the manual approach of going to the
supermarket for each item
...
Entry control loops are like the
security check before boarding a metro, where the luggage is checked
for any suspicious items
...

Types of Loops


For Loop: Used for a fixed number of iterations
...




Do While Loop: Similar to the While Loop but executes at least
once, regardless of the condition
...


Loops in C++: For Loop
In this video, we will be discussing the for loop in C++ programming
language
...

Why Use Loops?
We use loops when we have repetitive statements or iterations in our
program
...

General Syntax of For Loop
The general syntax of a for loop includes three expressions:
initialization, termination condition, and update
...

for (expression1; expression2; expression3) {

//

loop body}
Example
Let's say we want to print numbers from 1 to 10
...
With a for loop, we can
eliminate these repetitive statements
...
The termination
condition is i <= 10, meaning the loop will continue until i is no longer

less than or equal to 10
...
After
each iteration, we update i by incrementing it by 1
...
At some
point, it enters the for loop
...
Then, the
termination condition is checked
...

After the loop body is executed, the update expression is executed,
updating the variable
...

For example, in our previous example, the loop would execute 10 times,
printing the numbers 1 through 10
...

Assignment
As an assignment, try to write a program that takes in a number and
prints the sum of all numbers from 1 to that number
...
It might be difficult for beginners
to think of the logic, but you can always try and seek help from Google
if needed
...

The basic syntax of the for loop is simple, but you can do multiple tricky
things with it
...
In the next video, we'll discuss more
properties and tricky things you can do with the for loop
...
cp2" and write the following
code:
#include using namespace std;int main() {
for (int i = 1; i <= 10; i++) {
endl;

}

cout << i <<

return 0;}

Make sure to include the necessary headers and put the statement
inside the curly braces if you have more than one statement
...
Also, be careful when assigning a value
to the condition, as it might result in an infinite loop
...
In the next video, we'll explore more properties of the for loop
...
We will see how to write the for loop in different ways and
explore its capabilities with the help of programs and examples
...
We can write the for loop in many ways by manipulating
these expressions
...




More than one initialization can be done by separating them
with a comma
...




We can do tricky things with the loop variable in the update
expression, such as incrementing or decrementing by more
than one
...

When using conditions in a for loop, it's important to separate them
with commas
...
If
no conditions are added, it will result in an infinite loop
...

Increment and decrement expressions can be added either in the loop
body or as separate expressions separated by commas
...

Example:
for(int i=0, j=0; i<=5, j<3; i++, j++){
cout << i << " " << j << endl;

}



The loop will print values of i and j until j is less than 3
...




Adding a semicolon after the loop statement will terminate the
loop and anything after it will be considered as a separate
statement in the program
...


While Loops in C++ Programming Language
In this series of learning C++ programming language, we are discussing
loops in C++
...
In
this video, we will be discussing the while loop syntax, flowchart, and
the working of the while loop with the help of three or four programs
...


Why is it important for a fresher to get placed in a high paying
software job?
Getting placed in a high paying software job is not just about the salary;
it saves time
...
If you
have industry-relevant skills, then companies are ready to offer you a
high package
...

Thousands of students in their final year of graduates started from zero,
built industry-relevant skills, and got placed in high paying software
jobs
...
It is a proven
curriculum developed by IIT graduates who worked with top companies
like Amazon and Microsoft as product developers
...

If you want to get placed with a high package in software fields, you can
attend and make use of the free demo offered by Next Wave CCBP
Intensive team
...

What is a while loop in C++?
A while loop in C++ is a loop that executes a block of statements as
long as the condition given is true
...
It is not compulsory to write initialization or modifying
expressions, but it is mandatory to specify the termination condition;
otherwise, you may get an unexpected result
...
In this
example, we have specified the initialization, termination condition, and
modify expression within the block of statements
...

int i = 1;while (i < 3) {
i++;}

cout << i << "\n";

Output: 1 2
It is essential to update 'i' in the while loop
...

Flowchart of while loop
The working of a while loop can be shown with the help of a flowchart
...
Again, the condition would be checked, and this should be in
the loop
...


Use of while loop
We can use the while loop to put some validation on input
...
In this tutorial, we
will learn how to use while loops in C++ and explore some examples of
how they can be used
...
For example, we can ask
the user to enter a number greater than 6:
int n;
cout << "Enter a number greater than 6: ";
cin >> n;
while (n <= 6) {
cout << "Please enter a number greater than 6: ";
cin >> n;
}
cout << "Thanks!" << endl;
In the above example, if the user enters a number less than or equal to
6, the program will prompt them to enter a new number until a valid
number is entered
...
Here is a question: we
have a variable i, and in the while loop, we are writing a condition
termination, i = 1
...
What output will you
get? The answer is that it will print an infinite loop of 1 1 1 1
...

Here is another question: we are asking for the value of i, then in the
while loop, we are just writing i and printing i and i++
...
The range of
int is limited, so it will not print an infinite loop
...
When the condition becomes false, the loop exits
...
Once "i" becomes 0, it will become false
and the loop will stop
...
However, if we
enter 3 for "i", the loop will print 3, 2, 1
...

It's important to note that when we use the assignment operator
instead of the equality operator, the loop will become infinite
...
Here's the
modified program:
i = 1while i:

print("1")

If we enter 2 for "i", the loop will not run because 2 is not equal to 1
...

In order to fully understand while loops, it's important to experiment
with different conditions and try out different problems
...


What is the Do While Loop?
The do while loop is an exit-controlled loop in C++
...
Unlike the while loop, the body of the loop will be
executed at least once, even if the condition is false
...
This process will continue until the condition
becomes false
...
The program will start, and the body of the loop will be
executed irrespective of the condition
...
If it is true, the statements will be executed
again
...

Difference between Do While Loop and While Loop
The key difference between the do while loop and the while loop is that
the body of the do while loop is executed at least once, even if the
condition is false
...

Examples
Let's take a look at two programs to understand the difference between
the do while loop and the while loop
...
In the while loop, the body of the
loop is not executed as the condition is false
...

int number;do {

std::cout << "Enter a number

between 1 and 5: ";

std::cin >> number;} while

(number <= 1 || number >= 5);std::cout << "Thanks!"
<< std::endl;
In this program, the user is asked to enter a number between 1 and 5
...
Once a valid number is entered, the loop will
exit and print "Thanks!"

Do-While Loop
Do-while loop is used when you want to execute the loop body at least
once, regardless of the condition
...
If the entered number is not within
the range, the loop will repeat until a correct number is entered
...



Declare the variable outside the loop body if it is going to be
used outside the loop
...


Range-Based For Loop
The range-based for loop in C++11 works specifically on collections or
arrays, which are sequences of elements
...

Syntax
The syntax for the range-based for loop is as follows:
for (range_declaration : expression) {
//statements}
Here, the range_declaration is a variable declaration whose data type
should be the same as the collection or array
...
The statements inside
the loop will be executed repeatedly and sequentially for each element
in the collection or array
...


Drawbacks
One of the drawbacks of the range-based for loop is that it cannot be
used to target a specific element or index in the array
...


The Odin School Bootcamp
For those interested in becoming a full-stack software developer, the
Odin School is offering a six-month bootcamp for full-stack software
development
...
Scholarship
opportunities and an early bird discount are also available
...

The range-based for loop in C++ allows you to iterate over each
element in a collection or array
...
You can use auto to automatically deduce the
data type of the collection, making it easier to use
...

The variable declared in the loop is local to that loop and cannot be
redeclared within the loop or range expression
...
To declare a vector, use the syntax vector type> name = {values};


Title: C++ Programming Language Notes
Description: C++ is a general-purpose, object-oriented programming language. It was created by Bjarne Stroustrup at Bell Labs circa 1980. C++ is very similar to C (invented by Dennis Ritchie in the early 1970s). This C++ course is a beginner-friendly course that can help you grasp coding concepts even if you are an absolute beginner.