SlideShare a Scribd company logo
01
02
04
LECTURE 14
Modern C++
Today’s Agenda
01
03 Differences with standard c++
What is Modern C++ ?
05
What is C++ 11 , C++ 14 and C++ 17?
New features of C++
04
02
01
05
.
What Is Modern C++?
 C++ is one of the most widely used programming language in the world.
 It’s been around from the last 40 years and was initially much like C language
due to backward compatibility.
 But to meet modern computing requirements it was redesigned in the year
2011 and the name Modern C++ was given.
.
What Is Modern C++?
 After C++ 11, two newer versions of the standards have
been accepted:
. C++ 14: which is a bugfix to C++11.
. C++ 17: which adds some more new features to the language
 So now the term Modern C++ refers to C++11, C++14,
and C++17
.
Little History Of C++11/14/17?
 C++11 is a version of the standard for the programming
language C++.
 It was approved by the International Organization for Standardization (ISO)
on 12th
August 2011, replacing classic C++, and superseded by C++14 on 18th
August 2014.
 Then on 1st
Dec 2017 , C++ 17 was released with some
new modules and features.
.
Which Compiler Support C++17?
 All modern compilers except Turboc C++ 3.0 are now fully supporting C++ 17
standards .
 The most popular compilers are GCC C++, Clang C++, and Microsoft C++ and
following table lists their support for C++ 17:
Compiler C++17 Support
GCC8 Full Support For C++17
Clang C++ Implements all the features of C++17
Microsoft C++ Supports almost all of C++17
.
Which Compiler We will Use?
 Since we are using Code Blocks IDE which has support for GCC compiler so we
will be using GCC.
 Moreover , since there is not much difference in C++14 and C++17 so any
version of Code blocks which supports them will work
.
Modern C++ Features
 C++14/17 has lot of new concepts which were not present in classic C++.
 All these new features make Modern C++ programs type-safe and easier to
write, extend, and maintain.
These are listed on the next slide
.
Modern C++ Features
New Topics
New concepts of header files Lambda Expressions
Namespaces Rvalue References
Automatic type declaration Smart Pointer,Unique Pointer,Shared Pointer
New syntaxes of initialization Static cast, Reinterpret cast,Dynamic cast
Deleted functions Exception Handling
Nullptr Standard Template Library
Delegating constructors
Override and final
The String Class
.
What Is CodeBlock?
 Code::Blocks is a free, open-source cross-platform IDE (not a compiler) which
was designed to support C and C++ languages
 However now it also supports other languages, including Fortran and D.
.
What Compiler Code Blocks Uses?
 Code::Blocks supports multiple compilers like:
• GCC,
• MinGW,
• Digital Mars,
• Microsoft Visual C++,
• Borland C++,
• LLVM Clang,
• Watcom,
• LCC and
• the Intel C++ compiler.
.
Important Difference Between Standard
C++ and C++11/14/17
1. The names of all C++ header files do not contain .h extension
2. So <iostream.h> becomes <iostream> , <fstream.h> becomes <fstream> and so
on
3. For C language header files we still have the .h convention available but
recommendations are to use these header file names prefixed with the letter
‘c’ and dropping ‘ .h’.
4. So <math.h> becomes <cmath>, <stdlib.h> becomes <cstdlib> and so on
.
Important Difference Between Standard
C++ and C++11/14/17
5 All predefined object like cout , cin etc are now placed inside something called
namespace
6 The default namespace provided by c++ is called std
7 So instead of writing cout , the statement now becomes std::cout
.
Important Difference Between Standard
C++ and C++11/14/17
#include <iostream>
int main()
{
std::cout<<"Welcome To c++ 14";
return 0;
}
.
What Is A Namespace?
Before we discuss exactly what a namespace is, it is probably best to
consider a simple example of when and why we would need them.
Consider the following code:
#include <iostream>
int main()
{
int value;
value = 0;
double value;
value = 0.0;
std::cout<<value;
return 0;
}
Error Here!
.
What Is A Namespace?
 In each scope, a name can only represent one entity. So, there cannot be two
variables with the same name in the same scope.
 Using namespaces, we can create two variables or functions having the same
name
Syntax:
namespace <some_name>
{
entities
}
.
What Is A Namespace?
namespace first
{
int val;
}
namespace second
{
double val;
}
int main()
{
first::val=10;
second::val=1.5;
return 0;
}
.
Points To Remember
1. Namespace is a logical compartment used to avoid naming collisions.
2. Default namespace is global namespace and can access global data and
functions by proceeding (::) operator.
.
Points To Remember
3. We can create our own namespace and anything declared within namespace
has scope limited to namespace.
4 Creation of namespace is similar to creation of class.
.
Points To Remember
5. Namespace declarations can appear only at global scope
6. Namespace declarations don’t have access specifiers. (public or private)
7. No need to give semicolon after the closing brace of definition of namespace.
.
The Namespace “STD”
 The built in C++ library routines are kept in the standard namespace called std
 That includes stuff like cout, cin, string, vector etc.
 Since they are in namespace std so we need to apply the prefix std:: with each
one of them.
 Thus cout becomes std::cout , cin becomes std::cin and so on
.
The Namespace “STD”
#include <iostream>
int main()
{
int a,b,c;
std::cout<<“Enter 2 int”<<std::endl;
std::cin>>a>>b;
c=a+b;
std::cout<<“Nos are “<<a<<“ and “<<b<<std::endl;
std::cout<<“Their sum is “<<c;
return 0;
}
.
Avoiding “STD”
 The keyword using is used to introduce a name from a namespace into the
current declarative region.
 So using namespace std means that we are going to use classes or functions
(if any) from "std" namespace
 Thus we don't have to explicitly call the namespace to access them.
.
Modified Version
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<“Enter 2 int”<<endl;
cin>>a>>b;
c=a+b;
cout<<“Nos are “<<a<<“ and “<<b<<endl;
cout<<“Their sum is “<<c;
return 0;
}
.
New Data Types Added
 int : upgraded to 4 bytes
 bool : a special type of 1 byte in size for storing true/ false.
 wchar_t: a special data type for storing 2 bytes of characters
 long long : a new data type of integer family supporting size of 8bytes.
.
The “Auto” Keyword
• In Modern C++, the compiler can automatically determine the data type of a
variable at the point of declaration using it’s initialization expression:
• So,
int x = 4;
• can now be replaced with
auto x = 4;
• This is called automatic type deduction.
.
The “Auto” Keyword
• Also we can write
char *p=“Bhopal”;
as
auto p= “Bhopal”;
• This also applies to pointers of class type.
• So ,
Box *p = new Box;
can also be written as
auto p= new Box;
.
The “Auto” Keyword
• The auto keyword can also automatically detect a function’s return type
• For example:
auto add(int x, int y)
{
return x + y;
}
• Since x + y evaluates to an integer, the compiler will detect this function should
have a return type of int.
.
New Ways Of Initialization
• Modern C++,supports three basic ways to initialize a variable:
• Copy initialization
• Direct initialization
• Uniform initialization
.
New Ways Of Initialization
• Copy initialization : is done using assignment operator
int n = 5; // copy initialization
• Direct initialization : is done by using parenthesis.
int n(5); // direct initialization
.
New Ways Of Initialization
• Uniform initialization : is done using curly braces
int n { 5 }; // uniform initialization
If we leave the braces blank then compiler initializes
the variable to 0.
For Example
int n{ };
cout<<n ; // will display 0
.
In Class Initialization
• Modern C++ allows us to initialize data members at the point of declaration and this
is called In-Class Initialization
class Circle
{
int radius=10; // OK , from C++ 14 onwards
.
.
};
But , remember if we do not initialize them , their default
value will still be garbage
.
Range Based For Loop
• Modern C++ provides us an easy way to traverse an array called “Range Based For
Loop”.
• Syntax:
for(<data type> <var_name>: <array_name>)
{
//loop body
}
• Example:
int arr[ ]={10,20,30,40};
for(int x:arr)
cout<<x<<endl;
End of Lecture 14
Thank you
For any queries mail us @: scalive4u@gmail.com
Call us @ : 0755-4271659, 7879165533

More Related Content

PPTX
Lab 1.pptx
PPT
Basics of C++ computer language presentation.ppt
PPTX
Session 1 - c++ intro
PDF
C++ In One Day_Nho Vĩnh Share
PPTX
Lecture 1
PDF
fundamental of c++ for students of b.tech iii rd year student
PPTX
PPTX
computer programming omputer programming
Lab 1.pptx
Basics of C++ computer language presentation.ppt
Session 1 - c++ intro
C++ In One Day_Nho Vĩnh Share
Lecture 1
fundamental of c++ for students of b.tech iii rd year student
computer programming omputer programming

Similar to C++ LectuNSVAHDVQwyfkyuQWVHGWQUDKFEre-14.pptx (20)

DOCX
C tutorials
PPTX
UNIT - 1- Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
PPTX
Learning C++ - Introduction to c++ programming 1
PPTX
Introduction to cpp language and all the required information relating to it
PPTX
Introduction to c++ programming language
PPTX
C++ helps you to format the I/O operations like determining the number of dig...
PPTX
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
PPTX
Introduction-to-C-Part-1.pptx
PPTX
C++ programming language basic to advance level
PDF
The C++ Programming Language
PPTX
Advantage and Disadvantages of C++ programming.pptx
PDF
67404923-C-Programming-Tutorials-Doc.pdf
PPTX
1. Introduction to C++ and brief history
PDF
Introduction-to-C-Part-1.pdf
PDF
data structure book in c++ and c in easy wording
PPTX
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
PDF
Best Programming Course in Jalandhar - TechCADD Computer Education
PPT
Fp201 unit2 1
PPTX
C++ AND CATEGORIES OF SOFTWARE
PPTX
Return of c++
C tutorials
UNIT - 1- Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
Learning C++ - Introduction to c++ programming 1
Introduction to cpp language and all the required information relating to it
Introduction to c++ programming language
C++ helps you to format the I/O operations like determining the number of dig...
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1.pptx
C++ programming language basic to advance level
The C++ Programming Language
Advantage and Disadvantages of C++ programming.pptx
67404923-C-Programming-Tutorials-Doc.pdf
1. Introduction to C++ and brief history
Introduction-to-C-Part-1.pdf
data structure book in c++ and c in easy wording
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
Best Programming Course in Jalandhar - TechCADD Computer Education
Fp201 unit2 1
C++ AND CATEGORIES OF SOFTWARE
Return of c++
Ad

Recently uploaded (20)

PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
PDF
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
PPTX
How to Manage Global Discount in Odoo 18 POS
PPTX
Introduction and Scope of Bichemistry.pptx
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PPTX
IMMUNIZATION PROGRAMME pptx
PPTX
Software Engineering BSC DS UNIT 1 .pptx
PPTX
Strengthening open access through collaboration: building connections with OP...
PDF
Landforms and landscapes data surprise preview
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
PDF
5.Universal-Franchise-and-Indias-Electoral-System.pdfppt/pdf/8th class social...
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PDF
Types of Literary Text: Poetry and Prose
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...
Module 3: Health Systems Tutorial Slides S2 2025
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
How to Manage Global Discount in Odoo 18 POS
Introduction and Scope of Bichemistry.pptx
NOI Hackathon - Summer Edition - GreenThumber.pptx
Week 4 Term 3 Study Techniques revisited.pptx
Revamp in MTO Odoo 18 Inventory - Odoo Slides
IMMUNIZATION PROGRAMME pptx
Software Engineering BSC DS UNIT 1 .pptx
Strengthening open access through collaboration: building connections with OP...
Landforms and landscapes data surprise preview
Open Quiz Monsoon Mind Game Prelims.pptx
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
5.Universal-Franchise-and-Indias-Electoral-System.pdfppt/pdf/8th class social...
The Final Stretch: How to Release a Game and Not Die in the Process.
Types of Literary Text: Poetry and Prose
Ad

C++ LectuNSVAHDVQwyfkyuQWVHGWQUDKFEre-14.pptx

  • 2. Today’s Agenda 01 03 Differences with standard c++ What is Modern C++ ? 05 What is C++ 11 , C++ 14 and C++ 17? New features of C++ 04 02 01 05
  • 3. . What Is Modern C++?  C++ is one of the most widely used programming language in the world.  It’s been around from the last 40 years and was initially much like C language due to backward compatibility.  But to meet modern computing requirements it was redesigned in the year 2011 and the name Modern C++ was given.
  • 4. . What Is Modern C++?  After C++ 11, two newer versions of the standards have been accepted: . C++ 14: which is a bugfix to C++11. . C++ 17: which adds some more new features to the language  So now the term Modern C++ refers to C++11, C++14, and C++17
  • 5. . Little History Of C++11/14/17?  C++11 is a version of the standard for the programming language C++.  It was approved by the International Organization for Standardization (ISO) on 12th August 2011, replacing classic C++, and superseded by C++14 on 18th August 2014.  Then on 1st Dec 2017 , C++ 17 was released with some new modules and features.
  • 6. . Which Compiler Support C++17?  All modern compilers except Turboc C++ 3.0 are now fully supporting C++ 17 standards .  The most popular compilers are GCC C++, Clang C++, and Microsoft C++ and following table lists their support for C++ 17: Compiler C++17 Support GCC8 Full Support For C++17 Clang C++ Implements all the features of C++17 Microsoft C++ Supports almost all of C++17
  • 7. . Which Compiler We will Use?  Since we are using Code Blocks IDE which has support for GCC compiler so we will be using GCC.  Moreover , since there is not much difference in C++14 and C++17 so any version of Code blocks which supports them will work
  • 8. . Modern C++ Features  C++14/17 has lot of new concepts which were not present in classic C++.  All these new features make Modern C++ programs type-safe and easier to write, extend, and maintain. These are listed on the next slide
  • 9. . Modern C++ Features New Topics New concepts of header files Lambda Expressions Namespaces Rvalue References Automatic type declaration Smart Pointer,Unique Pointer,Shared Pointer New syntaxes of initialization Static cast, Reinterpret cast,Dynamic cast Deleted functions Exception Handling Nullptr Standard Template Library Delegating constructors Override and final The String Class
  • 10. . What Is CodeBlock?  Code::Blocks is a free, open-source cross-platform IDE (not a compiler) which was designed to support C and C++ languages  However now it also supports other languages, including Fortran and D.
  • 11. . What Compiler Code Blocks Uses?  Code::Blocks supports multiple compilers like: • GCC, • MinGW, • Digital Mars, • Microsoft Visual C++, • Borland C++, • LLVM Clang, • Watcom, • LCC and • the Intel C++ compiler.
  • 12. . Important Difference Between Standard C++ and C++11/14/17 1. The names of all C++ header files do not contain .h extension 2. So <iostream.h> becomes <iostream> , <fstream.h> becomes <fstream> and so on 3. For C language header files we still have the .h convention available but recommendations are to use these header file names prefixed with the letter ‘c’ and dropping ‘ .h’. 4. So <math.h> becomes <cmath>, <stdlib.h> becomes <cstdlib> and so on
  • 13. . Important Difference Between Standard C++ and C++11/14/17 5 All predefined object like cout , cin etc are now placed inside something called namespace 6 The default namespace provided by c++ is called std 7 So instead of writing cout , the statement now becomes std::cout
  • 14. . Important Difference Between Standard C++ and C++11/14/17 #include <iostream> int main() { std::cout<<"Welcome To c++ 14"; return 0; }
  • 15. . What Is A Namespace? Before we discuss exactly what a namespace is, it is probably best to consider a simple example of when and why we would need them. Consider the following code: #include <iostream> int main() { int value; value = 0; double value; value = 0.0; std::cout<<value; return 0; } Error Here!
  • 16. . What Is A Namespace?  In each scope, a name can only represent one entity. So, there cannot be two variables with the same name in the same scope.  Using namespaces, we can create two variables or functions having the same name Syntax: namespace <some_name> { entities }
  • 17. . What Is A Namespace? namespace first { int val; } namespace second { double val; } int main() { first::val=10; second::val=1.5; return 0; }
  • 18. . Points To Remember 1. Namespace is a logical compartment used to avoid naming collisions. 2. Default namespace is global namespace and can access global data and functions by proceeding (::) operator.
  • 19. . Points To Remember 3. We can create our own namespace and anything declared within namespace has scope limited to namespace. 4 Creation of namespace is similar to creation of class.
  • 20. . Points To Remember 5. Namespace declarations can appear only at global scope 6. Namespace declarations don’t have access specifiers. (public or private) 7. No need to give semicolon after the closing brace of definition of namespace.
  • 21. . The Namespace “STD”  The built in C++ library routines are kept in the standard namespace called std  That includes stuff like cout, cin, string, vector etc.  Since they are in namespace std so we need to apply the prefix std:: with each one of them.  Thus cout becomes std::cout , cin becomes std::cin and so on
  • 22. . The Namespace “STD” #include <iostream> int main() { int a,b,c; std::cout<<“Enter 2 int”<<std::endl; std::cin>>a>>b; c=a+b; std::cout<<“Nos are “<<a<<“ and “<<b<<std::endl; std::cout<<“Their sum is “<<c; return 0; }
  • 23. . Avoiding “STD”  The keyword using is used to introduce a name from a namespace into the current declarative region.  So using namespace std means that we are going to use classes or functions (if any) from "std" namespace  Thus we don't have to explicitly call the namespace to access them.
  • 24. . Modified Version #include <iostream> using namespace std; int main() { int a,b,c; cout<<“Enter 2 int”<<endl; cin>>a>>b; c=a+b; cout<<“Nos are “<<a<<“ and “<<b<<endl; cout<<“Their sum is “<<c; return 0; }
  • 25. . New Data Types Added  int : upgraded to 4 bytes  bool : a special type of 1 byte in size for storing true/ false.  wchar_t: a special data type for storing 2 bytes of characters  long long : a new data type of integer family supporting size of 8bytes.
  • 26. . The “Auto” Keyword • In Modern C++, the compiler can automatically determine the data type of a variable at the point of declaration using it’s initialization expression: • So, int x = 4; • can now be replaced with auto x = 4; • This is called automatic type deduction.
  • 27. . The “Auto” Keyword • Also we can write char *p=“Bhopal”; as auto p= “Bhopal”; • This also applies to pointers of class type. • So , Box *p = new Box; can also be written as auto p= new Box;
  • 28. . The “Auto” Keyword • The auto keyword can also automatically detect a function’s return type • For example: auto add(int x, int y) { return x + y; } • Since x + y evaluates to an integer, the compiler will detect this function should have a return type of int.
  • 29. . New Ways Of Initialization • Modern C++,supports three basic ways to initialize a variable: • Copy initialization • Direct initialization • Uniform initialization
  • 30. . New Ways Of Initialization • Copy initialization : is done using assignment operator int n = 5; // copy initialization • Direct initialization : is done by using parenthesis. int n(5); // direct initialization
  • 31. . New Ways Of Initialization • Uniform initialization : is done using curly braces int n { 5 }; // uniform initialization If we leave the braces blank then compiler initializes the variable to 0. For Example int n{ }; cout<<n ; // will display 0
  • 32. . In Class Initialization • Modern C++ allows us to initialize data members at the point of declaration and this is called In-Class Initialization class Circle { int radius=10; // OK , from C++ 14 onwards . . }; But , remember if we do not initialize them , their default value will still be garbage
  • 33. . Range Based For Loop • Modern C++ provides us an easy way to traverse an array called “Range Based For Loop”. • Syntax: for(<data type> <var_name>: <array_name>) { //loop body } • Example: int arr[ ]={10,20,30,40}; for(int x:arr) cout<<x<<endl;
  • 34. End of Lecture 14 Thank you For any queries mail us @: [email protected] Call us @ : 0755-4271659, 7879165533