SlideShare a Scribd company logo
C++ Language Basics
Objectives
In this chapter you will learn about
•History of C++
•Some drawbacks of C
•A simple C++ program
•Input and Output operators
•Variable declaration
•bool Datatype
•Typecasting
•The Reference –‘&’operator
C++
1979 - First Release It was called C with Classes
1983 Renamed to C++
1998 ANSI C++
2003 STL was added
2011 C++ 11
2014 C++14
2017 C++17
 C++ is a superset of C language.
 It supports everything what is there in C
and provides extra features.
Before we start with C++,
lets see some C questions
int a ;
int a ;
int main( )
{
printf("a = %d " , a);
}
int a = 5;
int a = 10;
int main( )
{
printf("a = %d " , a);
}
 An external declaration for an object is a definition if it has
an initializer.
 An external object declaration that does not have an
initializer, and does not contain the extern specifier, is a
tentative definition.
 If a definition for an object appears in a translation unit, any
tentative definitions are treated merely as redundant
declarations.
 If no definition for the object appears in the translation unit,
all its tentative definitions become a single definition with
initializer 0.
int main( )
{
const int x ;
printf("x = %d n",x);
}
C: It is not compulsory to initialize const;
C++: Constants should be initialized in C++.
int main( )
{
const int x = 5;
printf("Enter a number : ");
scanf(" %d" , &x);
printf("x = %d n",x);
}
 Scanf cannot verify if the argument is
const variable or not.
 It allows us to modify the value of const
variable.
#include <iostream>
int main( )
{
std::cout << "Hello World";
return 0;
}
#include <iostream>
int main( )
{
int num1 = 0;
int num2 = 0;
std::cout << "Enter two numbers :";
std::cin >> num1;
std::cin >> num2;
int sum = num1 + num2;
std::cout << sum;
return 0;
}
#include <iostream>
using namespace std;
int main( )
{
int num1 = 0;
int num2 = 0;
cout << "Enter two numbers :";
cin >> num1 >> num2;
int sum = num1 + num2;
cout << “Sum = “ << sum;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int regno;
char name[20];
cout << “Enter your reg no. :“ ;
cin >> regno;
cout << "Enter your name :“ ;
cin >> name;
cout << "REG NO : " << regno << endl ;
cout << "Name :" << name << endl;
return 0;
}
 The ‘cout’is an object of the class ‘ostream’
 It inserts data into the console output stream
 << - called the Insertion Operator or put to operator, It
directs the contents of the variable on its right to the
object on its left.
 The ‘cin’is an object of the class ‘istream’
 It extracts data from the console input stream
 >> - called the Extraction or get from operator, it takes
the value from the stream object on its left and places it
in the variable on its right.
 Use <iostream> instead of using <iostream.h>
 The <iostream> file provides support for all
console-related input –output stream based
operations
 using namespace std;
 ‘std’is known as the standard namespace and is
pre-defined
#include <iostream>
using namespace std;
int main( )
{
const int x = 5;
cout << "Enter a number : ";
cin >> x;
cout << "x =" << x;
}
#include <stdio.h>
int main( )
{
const int x = 5;
printf("Enter a number : “);
scanf(“ %d”,&x);
printf("x = %d” , x);
}
 C allows a variable to be declared only at the
beginning of a function (or to be more precise,
beginning of a block)
 C++ supports ‘anywhere declaration’ –before
the first use of the variable
int x;
cin>>x;
int y;
cin>>y;
int res = x + y;
cout<<res<<endl;
for(int i=0;i<10;++i)
cout<<i<<endl;
 “bool” is a new C++ data type
 It is used like a flag for signifying occurrence of
some condition
 Takes only two values defined by two new
keywords
• true – 1
• false - 0
bool powerof2(int
num)
{ // if only 1 bit is set
if(!(num & num-1))
return true;
else
return false;
}
bool search(int a[],int n,int key)
{
for(int i = 0 ; i < n ; i++)
if(a[i] == key)
return true;
return false;
}
 The following types of type-casting are supported
in C++
 double x = 10.5;
 int y1 = (int) x; // c -style casting
 cout<<y1<<endl;
 int y2 = int(x); // c++ -style casting(function style)
 cout<<y2<<endl;
 int y3 = static_cast<int>(x); //C++ 98
void update(int *a)
{
*++a;
printf("Update %d " , *a);
}
int main( )
{
int a = 5;
update(&a);
printf("Main %d n" , a);
}
void update(int a)
{
++a;
printf("Update %d " , a);
}
int main( )
{
int a = 5;
update(a);
printf("Main %d n" , a);
}
void myswap(int *a,int *b)
{
int *temp = a;
a = b;
b = temp;
printf("myswap a=%d b = %d n" , *a , *b);
}
int main( )
{
int a = 5 , b = 10;
myswap(&a , & b);
printf("Main a=%d b = %d n" , a , b);
}
 The previous two code snippets showed
us how easily we can go wrong with
pointer.
 The Reference ‘&’operator is used in C++ to
create aliases to other existing variables /
objects
TYPE &refName= varName;
int x = 10;
int &y = x;
cout<<x<<‘ ‘<<y<<endl;
++y;
cout<<x<<‘ ‘<<y<<endl;
10
x
y
int x = 10;
int y = x;
cout<<x<<‘ ‘<<y<<endl;
++y;
cout<<x<<‘ ‘<<y<<endl;
10
x
y
int x = 10;
int &y = x;
cout<<x<<‘ ‘<<y<<endl;
++y;
cout<<x<<‘ ‘<<y<<endl;
10
10
x
y
 A reference should always be initialized.
 A reference cannot refer to constant
literals. It can only refer to
objects(variables).
• int &reference;
• int &reference = 5;
• int a = 5, b = 10;
• int &reference = a + b;
• Once a reference is created, we can refer to that location using
either of the names.
• & is only used to create a reference.
• To refer to value of x using reference, we do not use &
CPP Language Basics - Reference
CPP Language Basics - Reference
CPP Language Basics - Reference
CPP Language Basics - Reference
void myswap(int a,int b)
{
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
int main()
{
int a = 10,b = 20;
myswap(a,b);
cout<<a<<'t'<<b<<endl;
return 0;
}
void myswap(int *a,int *b)
{
*a = *a ^ *b;
*b = *a ^ *b;
*a = *a ^ *b;
}
int main()
{
int a = 10,b = 20;
myswap(&a,&b);
cout<<a<<'t'<<b<<endl;
return 0;
}
Call by Value Call by Address
void myswap(int a,int b)
{
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
int main()
{
int a = 10,b = 20;
myswap(a,b);
cout<<a<<'t'<<b<<endl;
return 0;
}
void myswap(int &a,int &b)
{
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
int main()
{
int a = 10,b = 20;
myswap(a,b);
cout<<a<<'t'<<b<<endl;
return 0;
}
Call by Value Call by Reference
 The function call is made in the same
manner as Call By Value
• Whether a reference is taken for the actual
arguments
OR
• a new variable is created and the value is copied
is made transparent to the invoker of the function
CPP Language Basics - Reference
CPP Language Basics - Reference
CPP Language Basics - Reference
 Reference should always be initialised,
pointers need not be initialised.
 No NULL reference - A reference must always
refer to some object
 Pointers may be reassigned to refer to different
objects. A reference, however, always refers to
the object with which it is initialized
CPP Language Basics - Reference

More Related Content

PDF
Implementing String
PDF
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
PDF
Operator Overloading in C++
PPT
Functions in C++
PDF
LLVM Register Allocation (2nd Version)
PDF
Haskell study 15
PDF
LLVM Register Allocation
PPTX
LLVM Backend Porting
Implementing String
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Operator Overloading in C++
Functions in C++
LLVM Register Allocation (2nd Version)
Haskell study 15
LLVM Register Allocation
LLVM Backend Porting

What's hot (20)

PPT
OOP in C++
PPTX
Array of objects.pptx
PPTX
Understand more about C
PDF
Typescript in React: HOW & WHY?
PDF
OpenSSL Basic Function Call Flow
PPT
TypeScript Presentation
PPTX
GCC RTL and Machine Description
PDF
GDB Rocks!
PPTX
Templates in C++
PPTX
Inline Functions and Default arguments
PDF
中3女子が狂える本当に気持ちのいい constexpr
PPT
Strings
PPT
GCC compiler
PPTX
純粋関数型アルゴリズム入門
PPTX
Smart pointers
PDF
DWARF Data Representation
PPTX
Functions in c++
PPTX
Function Pointer
PPT
PPTX
Dynamic programming Basics
OOP in C++
Array of objects.pptx
Understand more about C
Typescript in React: HOW & WHY?
OpenSSL Basic Function Call Flow
TypeScript Presentation
GCC RTL and Machine Description
GDB Rocks!
Templates in C++
Inline Functions and Default arguments
中3女子が狂える本当に気持ちのいい constexpr
Strings
GCC compiler
純粋関数型アルゴリズム入門
Smart pointers
DWARF Data Representation
Functions in c++
Function Pointer
Dynamic programming Basics
Ad

Viewers also liked (18)

PPTX
INGENIERIA GEOGRAFICA Y AMBIENTAL
PPTX
El Hombre Y Su Comunidad (M.I)
PPTX
Mercurial Quick Tutorial
PDF
La tua europa
PDF
Growing a Data Pipeline for Analytics
PDF
Java and Java platforms
PPT
EVALUACION EDUCACION FISICA
PPTX
Managing the Maturity of Tourism Destinations: the Challenge of Governance an...
PDF
Kti efta mayasari
PPTX
PPTX
Understanding and using while in c++
PPT
Grade 10 flowcharting
DOCX
Evaluacion escala de rango 2016 2017
PPT
C++ basics
PDF
Materiali lapidei artificiali 4 - Architettura romana
PPT
Class and object in C++
INGENIERIA GEOGRAFICA Y AMBIENTAL
El Hombre Y Su Comunidad (M.I)
Mercurial Quick Tutorial
La tua europa
Growing a Data Pipeline for Analytics
Java and Java platforms
EVALUACION EDUCACION FISICA
Managing the Maturity of Tourism Destinations: the Challenge of Governance an...
Kti efta mayasari
Understanding and using while in c++
Grade 10 flowcharting
Evaluacion escala de rango 2016 2017
C++ basics
Materiali lapidei artificiali 4 - Architettura romana
Class and object in C++
Ad

Similar to CPP Language Basics - Reference (20)

PPTX
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
PPTX
C++ lectures all chapters in one slide.pptx
PPT
C++ Functions.ppt
PDF
C++ Nested loops, matrix and fuctions.pdf
PDF
C++ practical
PPTX
Presentations_PPT_ Unit-6_OOP.pptx
PPTX
Presentat ions_PPT_Unit-2_OOP.pptx
PPTX
Computational PhysicsssComputational Physics.pptx
PPT
Lecture 3 c++
PPTX
Computational Physics Cpp Portiiion.pptx
PPTX
C++ FUNCTIONS-1.pptx
PDF
54602399 c-examples-51-to-108-programe-ee01083101
PPT
Lecture2.ppt
PDF
C++ Programming - 4th Study
DOCX
code (1) thông tin nhập môn cntt hdsd.docx
PPT
C++ Language
PPTX
Presentation on C++ Programming Language
PPTX
CP 04.pptx
PDF
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
PDF
C++11 & C++14
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
C++ lectures all chapters in one slide.pptx
C++ Functions.ppt
C++ Nested loops, matrix and fuctions.pdf
C++ practical
Presentations_PPT_ Unit-6_OOP.pptx
Presentat ions_PPT_Unit-2_OOP.pptx
Computational PhysicsssComputational Physics.pptx
Lecture 3 c++
Computational Physics Cpp Portiiion.pptx
C++ FUNCTIONS-1.pptx
54602399 c-examples-51-to-108-programe-ee01083101
Lecture2.ppt
C++ Programming - 4th Study
code (1) thông tin nhập môn cntt hdsd.docx
C++ Language
Presentation on C++ Programming Language
CP 04.pptx
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
C++11 & C++14

More from Mohammed Sikander (20)

PDF
STL Containers in C++ : Sequence Container : Vector
PPTX
Strings in C - covers string functions
PDF
Smart Pointers, Modern Memory Management Techniques
PDF
Multithreading_in_C++ - std::thread, race condition
PDF
Python_Regular Expression
PPTX
Modern_CPP-Range-Based For Loop.pptx
PDF
Modern_cpp_auto.pdf
PPTX
Python Functions
PPTX
Python dictionary
PDF
Python exception handling
PDF
Python tuple
PDF
Python strings
PDF
Python set
PDF
Python list
PDF
Python Flow Control
PDF
Introduction to Python
PPTX
Pointer basics
PPTX
PPTX
File management
STL Containers in C++ : Sequence Container : Vector
Strings in C - covers string functions
Smart Pointers, Modern Memory Management Techniques
Multithreading_in_C++ - std::thread, race condition
Python_Regular Expression
Modern_CPP-Range-Based For Loop.pptx
Modern_cpp_auto.pdf
Python Functions
Python dictionary
Python exception handling
Python tuple
Python strings
Python set
Python list
Python Flow Control
Introduction to Python
Pointer basics
File management

Recently uploaded (20)

PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Transform Your Business with a Software ERP System
PPTX
history of c programming in notes for students .pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
System and Network Administration Chapter 2
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Essential Infomation Tech presentation.pptx
PDF
Understanding Forklifts - TECH EHS Solution
PDF
top salesforce developer skills in 2025.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Transform Your Business with a Software ERP System
history of c programming in notes for students .pptx
Odoo Companies in India – Driving Business Transformation.pdf
Reimagine Home Health with the Power of Agentic AI​
Design an Analysis of Algorithms I-SECS-1021-03
Navsoft: AI-Powered Business Solutions & Custom Software Development
How to Choose the Right IT Partner for Your Business in Malaysia
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Which alternative to Crystal Reports is best for small or large businesses.pdf
CHAPTER 2 - PM Management and IT Context
System and Network Administration Chapter 2
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Wondershare Filmora 15 Crack With Activation Key [2025
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Essential Infomation Tech presentation.pptx
Understanding Forklifts - TECH EHS Solution
top salesforce developer skills in 2025.pdf

CPP Language Basics - Reference

  • 2. Objectives In this chapter you will learn about •History of C++ •Some drawbacks of C •A simple C++ program •Input and Output operators •Variable declaration •bool Datatype •Typecasting •The Reference –‘&’operator
  • 3. C++ 1979 - First Release It was called C with Classes 1983 Renamed to C++ 1998 ANSI C++ 2003 STL was added 2011 C++ 11 2014 C++14 2017 C++17
  • 4.  C++ is a superset of C language.  It supports everything what is there in C and provides extra features.
  • 5. Before we start with C++, lets see some C questions
  • 6. int a ; int a ; int main( ) { printf("a = %d " , a); } int a = 5; int a = 10; int main( ) { printf("a = %d " , a); }
  • 7.  An external declaration for an object is a definition if it has an initializer.  An external object declaration that does not have an initializer, and does not contain the extern specifier, is a tentative definition.  If a definition for an object appears in a translation unit, any tentative definitions are treated merely as redundant declarations.  If no definition for the object appears in the translation unit, all its tentative definitions become a single definition with initializer 0.
  • 8. int main( ) { const int x ; printf("x = %d n",x); } C: It is not compulsory to initialize const; C++: Constants should be initialized in C++.
  • 9. int main( ) { const int x = 5; printf("Enter a number : "); scanf(" %d" , &x); printf("x = %d n",x); }
  • 10.  Scanf cannot verify if the argument is const variable or not.  It allows us to modify the value of const variable.
  • 11. #include <iostream> int main( ) { std::cout << "Hello World"; return 0; }
  • 12. #include <iostream> int main( ) { int num1 = 0; int num2 = 0; std::cout << "Enter two numbers :"; std::cin >> num1; std::cin >> num2; int sum = num1 + num2; std::cout << sum; return 0; }
  • 13. #include <iostream> using namespace std; int main( ) { int num1 = 0; int num2 = 0; cout << "Enter two numbers :"; cin >> num1 >> num2; int sum = num1 + num2; cout << “Sum = “ << sum; return 0; }
  • 14. #include <iostream> using namespace std; int main() { int regno; char name[20]; cout << “Enter your reg no. :“ ; cin >> regno; cout << "Enter your name :“ ; cin >> name; cout << "REG NO : " << regno << endl ; cout << "Name :" << name << endl; return 0; }
  • 15.  The ‘cout’is an object of the class ‘ostream’  It inserts data into the console output stream  << - called the Insertion Operator or put to operator, It directs the contents of the variable on its right to the object on its left.  The ‘cin’is an object of the class ‘istream’  It extracts data from the console input stream  >> - called the Extraction or get from operator, it takes the value from the stream object on its left and places it in the variable on its right.
  • 16.  Use <iostream> instead of using <iostream.h>  The <iostream> file provides support for all console-related input –output stream based operations  using namespace std;  ‘std’is known as the standard namespace and is pre-defined
  • 17. #include <iostream> using namespace std; int main( ) { const int x = 5; cout << "Enter a number : "; cin >> x; cout << "x =" << x; } #include <stdio.h> int main( ) { const int x = 5; printf("Enter a number : “); scanf(“ %d”,&x); printf("x = %d” , x); }
  • 18.  C allows a variable to be declared only at the beginning of a function (or to be more precise, beginning of a block)  C++ supports ‘anywhere declaration’ –before the first use of the variable int x; cin>>x; int y; cin>>y; int res = x + y; cout<<res<<endl; for(int i=0;i<10;++i) cout<<i<<endl;
  • 19.  “bool” is a new C++ data type  It is used like a flag for signifying occurrence of some condition  Takes only two values defined by two new keywords • true – 1 • false - 0 bool powerof2(int num) { // if only 1 bit is set if(!(num & num-1)) return true; else return false; } bool search(int a[],int n,int key) { for(int i = 0 ; i < n ; i++) if(a[i] == key) return true; return false; }
  • 20.  The following types of type-casting are supported in C++  double x = 10.5;  int y1 = (int) x; // c -style casting  cout<<y1<<endl;  int y2 = int(x); // c++ -style casting(function style)  cout<<y2<<endl;  int y3 = static_cast<int>(x); //C++ 98
  • 21. void update(int *a) { *++a; printf("Update %d " , *a); } int main( ) { int a = 5; update(&a); printf("Main %d n" , a); } void update(int a) { ++a; printf("Update %d " , a); } int main( ) { int a = 5; update(a); printf("Main %d n" , a); }
  • 22. void myswap(int *a,int *b) { int *temp = a; a = b; b = temp; printf("myswap a=%d b = %d n" , *a , *b); } int main( ) { int a = 5 , b = 10; myswap(&a , & b); printf("Main a=%d b = %d n" , a , b); }
  • 23.  The previous two code snippets showed us how easily we can go wrong with pointer.
  • 24.  The Reference ‘&’operator is used in C++ to create aliases to other existing variables / objects TYPE &refName= varName; int x = 10; int &y = x; cout<<x<<‘ ‘<<y<<endl; ++y; cout<<x<<‘ ‘<<y<<endl; 10 x y
  • 25. int x = 10; int y = x; cout<<x<<‘ ‘<<y<<endl; ++y; cout<<x<<‘ ‘<<y<<endl; 10 x y int x = 10; int &y = x; cout<<x<<‘ ‘<<y<<endl; ++y; cout<<x<<‘ ‘<<y<<endl; 10 10 x y
  • 26.  A reference should always be initialized.  A reference cannot refer to constant literals. It can only refer to objects(variables). • int &reference; • int &reference = 5; • int a = 5, b = 10; • int &reference = a + b;
  • 27. • Once a reference is created, we can refer to that location using either of the names. • & is only used to create a reference. • To refer to value of x using reference, we do not use &
  • 32. void myswap(int a,int b) { a = a ^ b; b = a ^ b; a = a ^ b; } int main() { int a = 10,b = 20; myswap(a,b); cout<<a<<'t'<<b<<endl; return 0; } void myswap(int *a,int *b) { *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b; } int main() { int a = 10,b = 20; myswap(&a,&b); cout<<a<<'t'<<b<<endl; return 0; } Call by Value Call by Address
  • 33. void myswap(int a,int b) { a = a ^ b; b = a ^ b; a = a ^ b; } int main() { int a = 10,b = 20; myswap(a,b); cout<<a<<'t'<<b<<endl; return 0; } void myswap(int &a,int &b) { a = a ^ b; b = a ^ b; a = a ^ b; } int main() { int a = 10,b = 20; myswap(a,b); cout<<a<<'t'<<b<<endl; return 0; } Call by Value Call by Reference
  • 34.  The function call is made in the same manner as Call By Value • Whether a reference is taken for the actual arguments OR • a new variable is created and the value is copied is made transparent to the invoker of the function
  • 38.  Reference should always be initialised, pointers need not be initialised.  No NULL reference - A reference must always refer to some object  Pointers may be reassigned to refer to different objects. A reference, however, always refers to the object with which it is initialized

Editor's Notes

  • #7: Try this in C and C++
  • #15: Program : 1_IO.cpp
  • #16: cin&amp;gt;&amp;gt;regno;No Need for format specifier or address of(&amp;) operator
  • #17: Basic information about namespace to be added Namespace.cpp
  • #20: 2_bool.cpp int main() { bool a = -5; cout &amp;lt;&amp;lt;&amp;quot;a = &amp;quot;&amp;lt;&amp;lt;a;//Print 1 return 0; }
  • #21: typecasting.cpp
  • #25: 3_reference.cpp
  • #26: 3_reference.cpp
  • #31: #include &amp;lt;iostream&amp;gt; using namespace std; C Style of Pass by Reference void update(int *x) { *x = *x + 3; cout &amp;lt;&amp;lt;&amp;quot;In update x = &amp;quot; &amp;lt;&amp;lt; *x &amp;lt;&amp;lt; endl; } int main( ){ int x = 5; update( &amp;x ); cout &amp;lt;&amp;lt;&amp;quot;In update x = &amp;quot; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; endl; }
  • #34: 4_swapref.cpp
  • #37: #include &amp;lt;iostream&amp;gt; using namespace std; //Constant References? int main() { int x = 5; const int &amp;a = x; cout &amp;lt;&amp;lt; x &amp;lt;&amp;lt;&amp;quot; &amp;quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl; a = 10; //Invalid. x = 20; cout &amp;lt;&amp;lt; x &amp;lt;&amp;lt;&amp;quot; &amp;quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl; return 0; }
  • #38: #include &amp;lt;iostream&amp;gt; using namespace std; //Constant References? int main() { const int x = 5; int &amp;a = x; //Error const int &amp;b = x; //Valid return 0; }