SlideShare una empresa de Scribd logo
1 de 22
Descargar para leer sin conexión
Basic Elements of C++
09/04/131 VIT - SCSE
By
G.SasiKumar., M.E., (Ph.D).,
Assistant Professor
School of Computing Science and Engineering
VIT University
Characters are used to form the words, numbers and
expressions.
 alphabets from A.....Z, a....z
all decimal digits from 0....9
characters , . ; : ?
‘ “ ! | /  ~ _ $ % # & ^
* - + < > ( ) [ ] { } Spaces
blank
New Line endl
09/04/132 VIT - SCSE
Character Set
Keywords and Identifiers
All keywords must be written in lowercase.
auto double int struct break
else long switch case enum register
Typedef char extern return union
const float short unsigned continue
for signed void default goto
sizeof volatile do if static while
Identifiers refer to the names of variables, functions and arrays.
These are user -defined names and consist of a sequence of letters
and digits.
09/04/133 VIT - SCSE
Data Types
09/04/134 VIT - SCSE
C++ Data Types
User Defined type
Structure
Union
Class
Enumeration
Built-in type Derived type
Array
Function
Pointer
Integral Floating
Character
Void
byte short int long
float double
Constants
Constants in C++ refer to fixed values that do not change
during the execution of a program.
C++ supports several types of constants as shown below: -
1. Numeric Constants
Integer Constants
Floating point (real) Constants
2. Character Constants
Single Character Constants
String Constants
09/04/135 VIT - SCSE
Integer Constants
Decimal integers consist of a set of digits from 0
through 9. The decimal integers can be positive or
negative.(base 10)
Octal integers consist of any combination of digits
from 0 through 7, with a leading zero.(base 8)
Hexadecimal integers consist of a sequence of digits 0
through 9 and alphabets from A (a) through F (f). The
letters 'A' (a) through 'F ' (f) represent the integers 10
through 15.(16)
09/04/136 VIT - SCSE
Floating-Point Constants
Floating-point constants are represented by numbers
containing fractional parts like in 549.4545.
Floating-point constants are also sometimes called as real
number constants.
09/04/137 VIT - SCSE
Single Character Constants
A character constant is a single character enclosed within a pair of single
quotes.
Example:
'A'
'3'
'?'
';'
' '
Constant ASCII value
'a' 97
'A' 65
'&' 38
';' 59
09/04/138 VIT - SCSE
String Constants
 A string constant is a sequence of characters enclosed
within a pair of double quotes.
The string constant may also include special characters,
numbers and blank spaces.
Example:
" Hello!"
" I'm going for shopping today. Will you come?"
" 549, The Mall, Shimla."
09/04/139 VIT - SCSE
Escape Sequences
Character Escape sequence
bell a
backspace b
horizontal tab t
vertical tab v
newline n
carriage return r
quotation mark "
apostrophe '
backslash 
null 0
09/04/1310 VIT - SCSE
Variables
A variable is an identifier that is used to represent a single data
item
Declaration
Definition
09/04/1311 VIT - SCSE
Operators
An operator is a symbol that tells the compiler to perform
specific mathematical or logical manipulations.
Arithmetic Operators
o Increment and Decrement Operators
Relational and Logical Operators
Assignment Operators
Ternary(Conditional) Operator
Sizeof Operator
Comma Operator
& Operator
 -> Operators(a->b -Member b of object pointed to by a )
09/04/1312 VIT - SCSE
Control Statements
Conditional Statements
If statement
If-else statement
Switch-case statement
Loop Statements
For loop
While loop
Do-while loop
Breaking control statements
Break
Continue
goto
09/04/1313 VIT - SCSE
Switch statement
switch(expression)
{ case constant_1:
statement;
break;
case constant_2:
statement;
break;
-----------------
case constant_n:
statement,
break;
default:
statement;
break;
}
09/04/1314 VIT - SCSE
//A program to display the name of the day in a week, depending upon the
number entered through the keyboard using the switch-case statement.
09/04/1315 VIT - SCSE
#include<iostream.h>
void main()
{
int day;
cout<<”Enter a number between 1 to
7”<<endl;
cin>>day;
switch(day)
{
case 1:
cout<<”Monday”<<endl;
break;
case 2:
cout<<”Tuesday”<<endl;
break;
case 3:
cout<<”Wednesday”<<endl;
break;
case 4:
cout<<”Thursday”<<endl;
break;
case 5:
cout<<”Friday”<<endl;
break;
case 6:
cout<<”Saturday”<<endl;
break;
case 7:
cout<<”Sunday”<<endl;
break;
}
}
For statement
//A program to find the sum and average of given numbers.
09/04/1316 VIT - SCSE
#include<iostream.h>
void main()
{
int n;
cout<<”How many
numbers?”<<endl;
cin>>n;
float sum=0;
float a=0;
float a;
for(int i=0; i<=n-1;i++)
{
cout<<”Enter a
number”<<endl;
cin>>a;
sum=sum+a;
}
float av;
av=sum/n;
cout<<”sum=”<<sum<<endl;
cout<<”Average=”<<av<<endl;
}
Nested For Statement
A program to display a name 15 times using the nested for loops.
#include<iostream.h>
void main()
{
cout<<”Nested for loop”;
for(int i=0; i<=2; i++)
{
cout<<i;
for(int j=0;j<=2;j++)
{
cout<<j;
for(int k=0;k<=2;k++)
{
cout<<k;
}}}}
09/04/1317 VIT - SCSE
While statement
{
sum+=digit;
digit++;
}
cout<<“1+2+3+.....
+100=“<<sum<<endl;
}
09/04/1318 VIT - SCSE
//program to find the sum
of the first 100 natural
numbers
#include<iostream.h>
void main()
{
int sum,digit;
sum=0;
digit=1;
while(digit<=100)
Do while loop
do
{
sum=sum+digit;
digit=digit+2;
}
while(digit<=max);
cout<<“2+4+...=“<<max<<“su
m=“;
}
09/04/1319 VIT - SCSE
//program to find the sum of
the even numbers using do-
while loop.
#include<iostream.h>
void main()
{
int max,sum,digit;
digit=2;
cout<<“enter a number“;
cin>>max;
sum=0;
Break statement
if(a<=0)
{
cout<<”Zero or negative
value found”;
break;
}
i++;
}
}
09/04/1320 VIT - SCSE
#include<iostream.h>
void main()
{
int a,i;
i=0;
while(i<=10)
{
cout<<”Enter a
number”<<endl;
cin>>a;
Continue statement
if(a<=0)
{
cout<<”Zero or negative
value found”;
continue;
}
i++;
}
}
09/04/1321 VIT - SCSE
#include<iostream.h>
void main()
{
int a,i;
i=0;
while(i<=10)
{
cout<<”Enter a
number”<<endl;
cin>>a;
Goto statement
output1:
cout<<”largest value=”<<a<<endl;
goto stop;
output2:
cout<<”largest value=”<<b<<endl;
stop:
getch();
}
09/04/1322 VIT - SCSE
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
cout<<”Enter two
numbers;
cin>>a>>b;
if(a>b)
goto output1;
else
goto output2;
goto label;

Más contenido relacionado

La actualidad más candente

Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programmingChitrank Dixit
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageRai University
 
Mca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageMca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageRai University
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c languageRai University
 
Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in Crgnikate
 
Bsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageBsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageRai University
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data typesPratik Devmurari
 

La actualidad más candente (20)

Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programming
 
Variable declaration
Variable declarationVariable declaration
Variable declaration
 
Variable declaration
Variable declarationVariable declaration
Variable declaration
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c language
 
Mca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageMca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c language
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c language
 
Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in C
 
Bsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageBsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c language
 
Character set of c
Character set of cCharacter set of c
Character set of c
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
 
Pengaturcaraan asas
Pengaturcaraan asasPengaturcaraan asas
Pengaturcaraan asas
 
C tokens
C tokensC tokens
C tokens
 
2 1 data
2 1  data2 1  data
2 1 data
 
Basics of c
Basics of cBasics of c
Basics of c
 
C language basics
C language basicsC language basics
C language basics
 
C# overview part 1
C# overview part 1C# overview part 1
C# overview part 1
 
Data type in c
Data type in cData type in c
Data type in c
 

Similar a 3 intro basic_elements

Similar a 3 intro basic_elements (20)

1.getting started with c
1.getting started with c1.getting started with c
1.getting started with c
 
PROGRAMMING IN C - Inroduction.pptx
PROGRAMMING IN C - Inroduction.pptxPROGRAMMING IN C - Inroduction.pptx
PROGRAMMING IN C - Inroduction.pptx
 
Chapter 13.1.1
Chapter 13.1.1Chapter 13.1.1
Chapter 13.1.1
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
Module 1 PCD.docx
Module 1 PCD.docxModule 1 PCD.docx
Module 1 PCD.docx
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
C++
C++C++
C++
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
CProgrammingTutorial
CProgrammingTutorialCProgrammingTutorial
CProgrammingTutorial
 
U2.ppt
U2.pptU2.ppt
U2.ppt
 
U2.ppt
U2.pptU2.ppt
U2.ppt
 
Cnotes
CnotesCnotes
Cnotes
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
T03 b basicioscanf
T03 b basicioscanfT03 b basicioscanf
T03 b basicioscanf
 
fds unit1.docx
fds unit1.docxfds unit1.docx
fds unit1.docx
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 

Más de Docent Education

Más de Docent Education (15)

17 files and streams
17 files and streams17 files and streams
17 files and streams
 
16 virtual function
16 virtual function16 virtual function
16 virtual function
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
 
13 exception handling
13 exception handling13 exception handling
13 exception handling
 
12 constructors invocation and data members initialization
12 constructors invocation and data members initialization12 constructors invocation and data members initialization
12 constructors invocation and data members initialization
 
12 constructors invocation and data members initialization
12 constructors invocation and data members initialization12 constructors invocation and data members initialization
12 constructors invocation and data members initialization
 
11 constructors in derived classes
11 constructors in derived classes11 constructors in derived classes
11 constructors in derived classes
 
10 inheritance
10 inheritance10 inheritance
10 inheritance
 
7 class objects
7 class objects7 class objects
7 class objects
 
6 pointers functions
6 pointers functions6 pointers functions
6 pointers functions
 
5 array
5 array5 array
5 array
 
4 Type conversion functions
4 Type conversion functions4 Type conversion functions
4 Type conversion functions
 
1 Intro Object Oriented Programming
1  Intro Object Oriented Programming1  Intro Object Oriented Programming
1 Intro Object Oriented Programming
 
2 Intro c++
2 Intro c++2 Intro c++
2 Intro c++
 
unit-1-intro
 unit-1-intro unit-1-intro
unit-1-intro
 

Último

KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
GenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation IncGenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation IncObject Automation
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIUdaiappa Ramachandran
 
Introduction to Quantum Computing
Introduction to Quantum ComputingIntroduction to Quantum Computing
Introduction to Quantum ComputingGDSC PJATK
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
Things you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceThings you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceMartin Humpolec
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxYounusS2
 
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdfJamie (Taka) Wang
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 

Último (20)

KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
GenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation IncGenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation Inc
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AI
 
Introduction to Quantum Computing
Introduction to Quantum ComputingIntroduction to Quantum Computing
Introduction to Quantum Computing
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
Things you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceThings you didn't know you can use in your Salesforce
Things you didn't know you can use in your Salesforce
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptx
 
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 

3 intro basic_elements

  • 1. Basic Elements of C++ 09/04/131 VIT - SCSE By G.SasiKumar., M.E., (Ph.D)., Assistant Professor School of Computing Science and Engineering VIT University
  • 2. Characters are used to form the words, numbers and expressions.  alphabets from A.....Z, a....z all decimal digits from 0....9 characters , . ; : ? ‘ “ ! | / ~ _ $ % # & ^ * - + < > ( ) [ ] { } Spaces blank New Line endl 09/04/132 VIT - SCSE Character Set
  • 3. Keywords and Identifiers All keywords must be written in lowercase. auto double int struct break else long switch case enum register Typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while Identifiers refer to the names of variables, functions and arrays. These are user -defined names and consist of a sequence of letters and digits. 09/04/133 VIT - SCSE
  • 4. Data Types 09/04/134 VIT - SCSE C++ Data Types User Defined type Structure Union Class Enumeration Built-in type Derived type Array Function Pointer Integral Floating Character Void byte short int long float double
  • 5. Constants Constants in C++ refer to fixed values that do not change during the execution of a program. C++ supports several types of constants as shown below: - 1. Numeric Constants Integer Constants Floating point (real) Constants 2. Character Constants Single Character Constants String Constants 09/04/135 VIT - SCSE
  • 6. Integer Constants Decimal integers consist of a set of digits from 0 through 9. The decimal integers can be positive or negative.(base 10) Octal integers consist of any combination of digits from 0 through 7, with a leading zero.(base 8) Hexadecimal integers consist of a sequence of digits 0 through 9 and alphabets from A (a) through F (f). The letters 'A' (a) through 'F ' (f) represent the integers 10 through 15.(16) 09/04/136 VIT - SCSE
  • 7. Floating-Point Constants Floating-point constants are represented by numbers containing fractional parts like in 549.4545. Floating-point constants are also sometimes called as real number constants. 09/04/137 VIT - SCSE
  • 8. Single Character Constants A character constant is a single character enclosed within a pair of single quotes. Example: 'A' '3' '?' ';' ' ' Constant ASCII value 'a' 97 'A' 65 '&' 38 ';' 59 09/04/138 VIT - SCSE
  • 9. String Constants  A string constant is a sequence of characters enclosed within a pair of double quotes. The string constant may also include special characters, numbers and blank spaces. Example: " Hello!" " I'm going for shopping today. Will you come?" " 549, The Mall, Shimla." 09/04/139 VIT - SCSE
  • 10. Escape Sequences Character Escape sequence bell a backspace b horizontal tab t vertical tab v newline n carriage return r quotation mark " apostrophe ' backslash null 0 09/04/1310 VIT - SCSE
  • 11. Variables A variable is an identifier that is used to represent a single data item Declaration Definition 09/04/1311 VIT - SCSE
  • 12. Operators An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. Arithmetic Operators o Increment and Decrement Operators Relational and Logical Operators Assignment Operators Ternary(Conditional) Operator Sizeof Operator Comma Operator & Operator  -> Operators(a->b -Member b of object pointed to by a ) 09/04/1312 VIT - SCSE
  • 13. Control Statements Conditional Statements If statement If-else statement Switch-case statement Loop Statements For loop While loop Do-while loop Breaking control statements Break Continue goto 09/04/1313 VIT - SCSE
  • 14. Switch statement switch(expression) { case constant_1: statement; break; case constant_2: statement; break; ----------------- case constant_n: statement, break; default: statement; break; } 09/04/1314 VIT - SCSE
  • 15. //A program to display the name of the day in a week, depending upon the number entered through the keyboard using the switch-case statement. 09/04/1315 VIT - SCSE #include<iostream.h> void main() { int day; cout<<”Enter a number between 1 to 7”<<endl; cin>>day; switch(day) { case 1: cout<<”Monday”<<endl; break; case 2: cout<<”Tuesday”<<endl; break; case 3: cout<<”Wednesday”<<endl; break; case 4: cout<<”Thursday”<<endl; break; case 5: cout<<”Friday”<<endl; break; case 6: cout<<”Saturday”<<endl; break; case 7: cout<<”Sunday”<<endl; break; } }
  • 16. For statement //A program to find the sum and average of given numbers. 09/04/1316 VIT - SCSE #include<iostream.h> void main() { int n; cout<<”How many numbers?”<<endl; cin>>n; float sum=0; float a=0; float a; for(int i=0; i<=n-1;i++) { cout<<”Enter a number”<<endl; cin>>a; sum=sum+a; } float av; av=sum/n; cout<<”sum=”<<sum<<endl; cout<<”Average=”<<av<<endl; }
  • 17. Nested For Statement A program to display a name 15 times using the nested for loops. #include<iostream.h> void main() { cout<<”Nested for loop”; for(int i=0; i<=2; i++) { cout<<i; for(int j=0;j<=2;j++) { cout<<j; for(int k=0;k<=2;k++) { cout<<k; }}}} 09/04/1317 VIT - SCSE
  • 18. While statement { sum+=digit; digit++; } cout<<“1+2+3+..... +100=“<<sum<<endl; } 09/04/1318 VIT - SCSE //program to find the sum of the first 100 natural numbers #include<iostream.h> void main() { int sum,digit; sum=0; digit=1; while(digit<=100)
  • 19. Do while loop do { sum=sum+digit; digit=digit+2; } while(digit<=max); cout<<“2+4+...=“<<max<<“su m=“; } 09/04/1319 VIT - SCSE //program to find the sum of the even numbers using do- while loop. #include<iostream.h> void main() { int max,sum,digit; digit=2; cout<<“enter a number“; cin>>max; sum=0;
  • 20. Break statement if(a<=0) { cout<<”Zero or negative value found”; break; } i++; } } 09/04/1320 VIT - SCSE #include<iostream.h> void main() { int a,i; i=0; while(i<=10) { cout<<”Enter a number”<<endl; cin>>a;
  • 21. Continue statement if(a<=0) { cout<<”Zero or negative value found”; continue; } i++; } } 09/04/1321 VIT - SCSE #include<iostream.h> void main() { int a,i; i=0; while(i<=10) { cout<<”Enter a number”<<endl; cin>>a;
  • 22. Goto statement output1: cout<<”largest value=”<<a<<endl; goto stop; output2: cout<<”largest value=”<<b<<endl; stop: getch(); } 09/04/1322 VIT - SCSE #include<iostream.h> #include<conio.h> void main() { int a,b; cout<<”Enter two numbers; cin>>a>>b; if(a>b) goto output1; else goto output2; goto label;