SlideShare a Scribd company logo
1 of 34
Download to read offline
Keywords, Identifiers ,
Datatypes
Unit-1
UGCA1909
Character Set
► As every language contains a set of characters used to construct words, statements, etc.,
► C++ language also has a set of characters which include alphabets, digits,
and special symbols. C++ language supports a total of 256 characters.
► C++ language character set contains the following set of characters...
1. Alphabets
2. Digits
3. Special Symbols
1.Alphabets
► C++ language supports all the alphabets from the English language. Lower and upper
case letters together support 52 alphabets.
► lower case letters - a to z
► UPPER CASE LETTERS - A to Z
2.Digits
► C++ language supports 10 digits which are used to construct numerical values in C
language.
► Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
3. Special Symbols
► C++ language supports a rich set of special symbols that include symbols to perform
mathematical operations, to check conditions, white spaces, backspaces, and other
special symbols.
► Special Symbols - ~ @ # $ % ^ & * ( ) _ - + = { } [ ] ; : ' " / ? . > , <  | tab
newline space NULL bell backspace verticaltab etc.,
C Tokens
► Every smallest individual unit of a c program is called token.
► Every instruction in a c program is a collection of tokens.
► Tokens are used to construct c++ programs and they are said to the basic
building blocks of a c++ program.
► In a c++ program tokens may contain the following...
► Keywords
► Identifiers
► Operators
► Special Symbols
► Constants
► Strings
► Data values
C Keywords
► Keywords are the reserved words with predefined meaning which already known to
the compiler.
► C++ programming also has words with a specific meaning which are used to construct c
program instructions.
► Keywords are also known as reserved words in C++ programming language.
► In the C++ programming language, there are 32 keywords.
Properties of Keywords
► All the keywords in C++ programming language are defined as lowercase
letters so they must be used only in lowercase letters
► Every keyword has a specific meaning, users can not change that meaning.
► Keywords can not be used as user-defined names like variable, functions,
arrays, pointers, etc...
► Every keyword in C++ programming language represents something or
specifies some kind of action to be performed by the compiler.
Keywords in C
C Identifiers
► The identifier is a user-defined name of an entity to identify it
uniquely during the program execution.
► An identifier is a collection of characters which acts as the name of variable,
function, array, pointer, structure, etc...
► Example
int marks;
Char c;
Float b;
Rules for Creating Identifiers
► An identifier can contain letters (UPPERCASE and lowercase), numeric &
underscore symbol only.
► An identifier should not start with a numerical value. It can start with a letter
or an underscore.
► We should not use any special symbols in between the identifier even
whitespace. However, the only underscore symbol is allowed.
► Keywords should not be used as identifiers.
► There is no limit for the length of an identifier. However, the compiler
considers the first 31 characters only.
► An identifier must be unique in its scope.
Rules for Creating Identifiers for better
programming
► The identifier must be meaningful to describe the entity.
► Since starting with an underscore may create conflict with system names, so
we avoid starting an identifier with an underscore.
► We start every identifier with a lowercase letter. If an identifier contains
more than one word then the first word starts with a lowercase letter and
second word onwards first letter is used as an UPPERCASE letter. We can also
use an underscore to separate multiple words in an identifier.
C++ data types
► Data types in the c programming language are used to specify what kind of
value can be stored in a variable.
► The memory size and type of the value of a variable are determined by the
variable data type.
► In a c program, each variable or constant or array must have a data type and
this data type specifies how much memory is to be allocated and what type of
values are to be stored in that variable or constant or array.
Types
► In the c programming language, data types are classified as follows...
► Primary data types (Basic data types OR Predefined data types)
► Derived data types (Secondary data types OR User-defined data types)
► Enumeration data types
► Void data type
DataTypes
Primary data types
► The primary data types in the C programming language are the basic data
types.
► All the primary data types are already defined in the system.
► Primary data types are also called as Built-In data types.
► The following are the primary data types in c programming language...
► Integer data type
► Floating Point data type
► Double data type
► Character data type
Integer Data type
► The integer data type is a set of whole numbers.
► Every integer value does not have the decimal value.
► We use the keyword "int" to represent integer data type in c++.
► We use the keyword int to declare the variables and to specify the return
type of a function.
► The integer data type is used with different type modifiers like short, long,
signed and unsigned.
The following table provides complete details about
the integer data type.
Floating Point data types
► Floating-point data types are a set of numbers with the decimal value. Every
floating-point value must contain the decimal value.
► The floating-point data type has two variants...
► float
► double
► We use the keyword "float" to represent floating-point data type and "double" to
represent double data type in c++.
► Both float and double are similar but they differ in the number of decimal places.
► The float value contains 6 decimal places whereas double value contains 15 or 19
decimal places.
floating-point data types
Character data type
► The character data type is a character enclosed in single quotations.
► The following table provides complete details about the character data type.
Other datatypes
► void data type
The void data type means nothing or no value. Generally, the void is used to specify a function which
does not return any value. We also use the void data type to specify empty parameters of a function.
► Enumerated data type
An enumerated data type is a user-defined data type that consists of integer constants and each integer
constant is given a name. The keyword "enum" is used to define the enumerated data type.
enum week{sunday, monday, tuesday, wednesday, thursday, friday, saturday};
enum week day;
► Derived data types
Derived data types are user-defined data types. The derived data types are also called as user-defined
data types or secondary data types. In the c++ programming language, the derived data types are
created using the following concepts...
► Arrays
► Structures
► Unions
► Enumeration
C++ Variables
► Variables in a c++ programming language are the named memory locations
where the user can store different values of the same datatype during the
program execution.
► That means a variable is a name given to a memory location in which we can
store different values of the same data type.
► In other words, a variable can be defined as a storage container to hold
values of the same datatype during the program execution.
► Declaration Syntax:
datatype variableName;
► Example
int number;
The above declaration tells to the compiler that allocates 2 bytes of memory with the
name number and allows only integer values into that memory location.
The following are the rules to specify a
variable name...
► A variable name may contain letters, digits and underscore symbol.
► Variable name should not start with a digit.
► Keywords should not be used as variable names.
► A variable name should not contain any special symbols except underscore(_).
► A variable name can be of any length but compiler considers only the first 31
characters of the variable name.
C Constants
► A constant is a named memory location which holds only one value throughout
the program execution.
► In C programming language, a constant is similar to the variable but the
constant hold only one value during the program execution.
► That means, once a value is assigned to the constant, that value can't be
changed during the program execution.
► Once the value is assigned to the constant, it is fixed throughout the program.
Types of Constants
Examples
► Integer constants
► An integer constant can be a decimal integer or octal integer or hexadecimal
integer.
► A decimal integer value is specified as direct integer value whereas octal integer
value is prefixed with 'o' and hexadecimal value is prefixed with 'OX’.
► Example
► 125 -----> Decimal Integer Constant
► O76 -----> Octal Integer Constant
► OX3A -----> Hexa Decimal Integer Constant
► Floating Point constants
► A floating-point constant must contain both integer and decimal parts. Some times
it may also contain the exponent part. When a floating-point constant is
represented in exponent form, the value must be suffixed with 'e' or 'E’.
► Example
► The floating-point value 3.14 is represented as 3E-14 in exponent form.
► Character Constants
► A character constant is a symbol enclosed in single quotation. A character constant has a
maximum length of one character.
► Example
► 'A'
► '2'
► '+’
► Escape sequences
► In the C++ programming language, there are some predefined character constants called
escape sequences. Every escape sequence has its own special functionality and every
escape sequence is prefixed with '' symbol. These escape sequences are used in cout.
► String Constants
► A string constant is a collection of characters, digits, special symbols and escape
sequences that are enclosed in double quotations.
► We define string constant in a single
► “Hello”
Creating constants in C++
► In a c programming language, constants can be created using two concepts...
► Using the 'const' keyword
► Using '#define' preprocessor
Using the 'const' keyword
► We create a constant of any datatype using 'const' keyword. To create a constant,
we prefix the variable declaration with 'const' keyword.
► The general syntax for creating constant using 'const' keyword is as follows...
► const datatype constantName ;
OR
► const datatype constantName = value ;
► Example
► const int x = 10 ;
► Here, 'x' is a integer constant with fixed value 10.
Example Program
#include<iostream.h>
#include<conio.h>
void main(){
int i = 9 ;
const int x = 10 ;
i = 15 ;
x = 100 ; // creates an error
cout<< “i=“<<i<<“n x=“<< x ;
}
Using '#define' preprocessor
► We can also create constants using '#define' preprocessor directive. When we create
constant using this preprocessor directive it must be defined at the beginning of the
program (because all the preprocessor directives must be written before the global
declaration).
► We use the following syntax to create constant using '#define' preprocessor
directive...
► #define CONSTANTNAME value
► Example
► #define PI 3.14
► Here, PI is a constant with value 3.14
Example Program
#include<iostream.h>
#include<conio.h>
#define PI 3.14
void main(){
int r, area ;
cout<<"Please enter the radius of circle : " ;
cin>>r;
area = PI * (r * r) ;
cout<<"Area of the circle “<<area ;
}
C++ Expressions
► In any programming language, if we want to perform any calculation or to
frame any condition etc., we use a set of symbols to perform the task. These
set of symbols makes an expression.
► An expression is a collection of operators and operands that represents a
specific value.
► In the above definition, an operator is a symbol that performs tasks like
arithmetic operations, logical operations, and conditional operations, etc.
► Operands are the values on which the operators perform the task.
► Example:
► c=a+b

More Related Content

What's hot (20)

File in C language
File in C languageFile in C language
File in C language
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
File Management in C
File Management in CFile Management in C
File Management in C
 
C tokens
C tokensC tokens
C tokens
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
 
C functions
C functionsC functions
C functions
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Data types in C language
Data types in C languageData types in C language
Data types in C language
 
structured programming
structured programmingstructured programming
structured programming
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 

Similar to Keywords, identifiers ,datatypes 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 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
 
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
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c languageRai University
 
5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt5-Lec - Datatypes.ppt
5-Lec - Datatypes.pptAqeelAbbas94
 
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 JyothiSowmyaJyothi3
 
C presentation book
C presentation bookC presentation book
C presentation bookkrunal1210
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data typesPratik Devmurari
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorialMohit Saini
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C ProgrammingKamal Acharya
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic FundamentalsDivyaR219113
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introductionnikshaikh786
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxMamataAnilgod
 
C PROGRAMMING LANGUAGE.pptx
 C PROGRAMMING LANGUAGE.pptx C PROGRAMMING LANGUAGE.pptx
C PROGRAMMING LANGUAGE.pptxAnshSrivastava48
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 

Similar to Keywords, identifiers ,datatypes in C++ (20)

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
 
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
 
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
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt
 
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
 
C presentation book
C presentation bookC presentation book
C presentation book
 
PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
Constants variables data_types
Constants variables data_typesConstants variables data_types
Constants variables data_types
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
 
C
CC
C
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic Fundamentals
 
All C ppt.ppt
All C ppt.pptAll C ppt.ppt
All C ppt.ppt
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptx
 
C PROGRAMMING LANGUAGE.pptx
 C PROGRAMMING LANGUAGE.pptx C PROGRAMMING LANGUAGE.pptx
C PROGRAMMING LANGUAGE.pptx
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 

Recently uploaded

How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryCeline George
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17Celine George
 
factors influencing drug absorption-final-2.pptx
factors influencing drug absorption-final-2.pptxfactors influencing drug absorption-final-2.pptx
factors influencing drug absorption-final-2.pptxSanjay Shekar
 
Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdfFinancial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdfMinawBelay
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesRased Khan
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfmstarkes24
 
Behavioral-sciences-dr-mowadat rana (1).pdf
Behavioral-sciences-dr-mowadat rana (1).pdfBehavioral-sciences-dr-mowadat rana (1).pdf
Behavioral-sciences-dr-mowadat rana (1).pdfaedhbteg
 
Discover the Dark Web .pdf InfosecTrain
Discover the Dark Web .pdf  InfosecTrainDiscover the Dark Web .pdf  InfosecTrain
Discover the Dark Web .pdf InfosecTraininfosec train
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...Nguyen Thanh Tu Collection
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticspragatimahajan3
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45MysoreMuleSoftMeetup
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Celine George
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxNehaChandwani11
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxCapitolTechU
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatmentsaipooja36
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the lifeNitinDeodare
 

Recently uploaded (20)

How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 Inventory
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
factors influencing drug absorption-final-2.pptx
factors influencing drug absorption-final-2.pptxfactors influencing drug absorption-final-2.pptx
factors influencing drug absorption-final-2.pptx
 
Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdfFinancial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
Behavioral-sciences-dr-mowadat rana (1).pdf
Behavioral-sciences-dr-mowadat rana (1).pdfBehavioral-sciences-dr-mowadat rana (1).pdf
Behavioral-sciences-dr-mowadat rana (1).pdf
 
Discover the Dark Web .pdf InfosecTrain
Discover the Dark Web .pdf  InfosecTrainDiscover the Dark Web .pdf  InfosecTrain
Discover the Dark Web .pdf InfosecTrain
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptx
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdfPost Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
 

Keywords, identifiers ,datatypes in C++

  • 2. Character Set ► As every language contains a set of characters used to construct words, statements, etc., ► C++ language also has a set of characters which include alphabets, digits, and special symbols. C++ language supports a total of 256 characters. ► C++ language character set contains the following set of characters... 1. Alphabets 2. Digits 3. Special Symbols
  • 3. 1.Alphabets ► C++ language supports all the alphabets from the English language. Lower and upper case letters together support 52 alphabets. ► lower case letters - a to z ► UPPER CASE LETTERS - A to Z 2.Digits ► C++ language supports 10 digits which are used to construct numerical values in C language. ► Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 3. Special Symbols ► C++ language supports a rich set of special symbols that include symbols to perform mathematical operations, to check conditions, white spaces, backspaces, and other special symbols. ► Special Symbols - ~ @ # $ % ^ & * ( ) _ - + = { } [ ] ; : ' " / ? . > , < | tab newline space NULL bell backspace verticaltab etc.,
  • 4. C Tokens ► Every smallest individual unit of a c program is called token. ► Every instruction in a c program is a collection of tokens. ► Tokens are used to construct c++ programs and they are said to the basic building blocks of a c++ program. ► In a c++ program tokens may contain the following... ► Keywords ► Identifiers ► Operators ► Special Symbols ► Constants ► Strings ► Data values
  • 5. C Keywords ► Keywords are the reserved words with predefined meaning which already known to the compiler. ► C++ programming also has words with a specific meaning which are used to construct c program instructions. ► Keywords are also known as reserved words in C++ programming language. ► In the C++ programming language, there are 32 keywords.
  • 6. Properties of Keywords ► All the keywords in C++ programming language are defined as lowercase letters so they must be used only in lowercase letters ► Every keyword has a specific meaning, users can not change that meaning. ► Keywords can not be used as user-defined names like variable, functions, arrays, pointers, etc... ► Every keyword in C++ programming language represents something or specifies some kind of action to be performed by the compiler.
  • 8. C Identifiers ► The identifier is a user-defined name of an entity to identify it uniquely during the program execution. ► An identifier is a collection of characters which acts as the name of variable, function, array, pointer, structure, etc... ► Example int marks; Char c; Float b;
  • 9. Rules for Creating Identifiers ► An identifier can contain letters (UPPERCASE and lowercase), numeric & underscore symbol only. ► An identifier should not start with a numerical value. It can start with a letter or an underscore. ► We should not use any special symbols in between the identifier even whitespace. However, the only underscore symbol is allowed. ► Keywords should not be used as identifiers. ► There is no limit for the length of an identifier. However, the compiler considers the first 31 characters only. ► An identifier must be unique in its scope.
  • 10. Rules for Creating Identifiers for better programming ► The identifier must be meaningful to describe the entity. ► Since starting with an underscore may create conflict with system names, so we avoid starting an identifier with an underscore. ► We start every identifier with a lowercase letter. If an identifier contains more than one word then the first word starts with a lowercase letter and second word onwards first letter is used as an UPPERCASE letter. We can also use an underscore to separate multiple words in an identifier.
  • 11. C++ data types ► Data types in the c programming language are used to specify what kind of value can be stored in a variable. ► The memory size and type of the value of a variable are determined by the variable data type. ► In a c program, each variable or constant or array must have a data type and this data type specifies how much memory is to be allocated and what type of values are to be stored in that variable or constant or array.
  • 12. Types ► In the c programming language, data types are classified as follows... ► Primary data types (Basic data types OR Predefined data types) ► Derived data types (Secondary data types OR User-defined data types) ► Enumeration data types ► Void data type
  • 14. Primary data types ► The primary data types in the C programming language are the basic data types. ► All the primary data types are already defined in the system. ► Primary data types are also called as Built-In data types. ► The following are the primary data types in c programming language... ► Integer data type ► Floating Point data type ► Double data type ► Character data type
  • 15.
  • 16. Integer Data type ► The integer data type is a set of whole numbers. ► Every integer value does not have the decimal value. ► We use the keyword "int" to represent integer data type in c++. ► We use the keyword int to declare the variables and to specify the return type of a function. ► The integer data type is used with different type modifiers like short, long, signed and unsigned.
  • 17. The following table provides complete details about the integer data type.
  • 18. Floating Point data types ► Floating-point data types are a set of numbers with the decimal value. Every floating-point value must contain the decimal value. ► The floating-point data type has two variants... ► float ► double ► We use the keyword "float" to represent floating-point data type and "double" to represent double data type in c++. ► Both float and double are similar but they differ in the number of decimal places. ► The float value contains 6 decimal places whereas double value contains 15 or 19 decimal places.
  • 20. Character data type ► The character data type is a character enclosed in single quotations. ► The following table provides complete details about the character data type.
  • 21. Other datatypes ► void data type The void data type means nothing or no value. Generally, the void is used to specify a function which does not return any value. We also use the void data type to specify empty parameters of a function. ► Enumerated data type An enumerated data type is a user-defined data type that consists of integer constants and each integer constant is given a name. The keyword "enum" is used to define the enumerated data type. enum week{sunday, monday, tuesday, wednesday, thursday, friday, saturday}; enum week day; ► Derived data types Derived data types are user-defined data types. The derived data types are also called as user-defined data types or secondary data types. In the c++ programming language, the derived data types are created using the following concepts... ► Arrays ► Structures ► Unions ► Enumeration
  • 22. C++ Variables ► Variables in a c++ programming language are the named memory locations where the user can store different values of the same datatype during the program execution. ► That means a variable is a name given to a memory location in which we can store different values of the same data type. ► In other words, a variable can be defined as a storage container to hold values of the same datatype during the program execution. ► Declaration Syntax: datatype variableName; ► Example int number; The above declaration tells to the compiler that allocates 2 bytes of memory with the name number and allows only integer values into that memory location.
  • 23. The following are the rules to specify a variable name... ► A variable name may contain letters, digits and underscore symbol. ► Variable name should not start with a digit. ► Keywords should not be used as variable names. ► A variable name should not contain any special symbols except underscore(_). ► A variable name can be of any length but compiler considers only the first 31 characters of the variable name.
  • 24. C Constants ► A constant is a named memory location which holds only one value throughout the program execution. ► In C programming language, a constant is similar to the variable but the constant hold only one value during the program execution. ► That means, once a value is assigned to the constant, that value can't be changed during the program execution. ► Once the value is assigned to the constant, it is fixed throughout the program.
  • 27. ► Integer constants ► An integer constant can be a decimal integer or octal integer or hexadecimal integer. ► A decimal integer value is specified as direct integer value whereas octal integer value is prefixed with 'o' and hexadecimal value is prefixed with 'OX’. ► Example ► 125 -----> Decimal Integer Constant ► O76 -----> Octal Integer Constant ► OX3A -----> Hexa Decimal Integer Constant ► Floating Point constants ► A floating-point constant must contain both integer and decimal parts. Some times it may also contain the exponent part. When a floating-point constant is represented in exponent form, the value must be suffixed with 'e' or 'E’. ► Example ► The floating-point value 3.14 is represented as 3E-14 in exponent form.
  • 28. ► Character Constants ► A character constant is a symbol enclosed in single quotation. A character constant has a maximum length of one character. ► Example ► 'A' ► '2' ► '+’ ► Escape sequences ► In the C++ programming language, there are some predefined character constants called escape sequences. Every escape sequence has its own special functionality and every escape sequence is prefixed with '' symbol. These escape sequences are used in cout. ► String Constants ► A string constant is a collection of characters, digits, special symbols and escape sequences that are enclosed in double quotations. ► We define string constant in a single ► “Hello”
  • 29. Creating constants in C++ ► In a c programming language, constants can be created using two concepts... ► Using the 'const' keyword ► Using '#define' preprocessor
  • 30. Using the 'const' keyword ► We create a constant of any datatype using 'const' keyword. To create a constant, we prefix the variable declaration with 'const' keyword. ► The general syntax for creating constant using 'const' keyword is as follows... ► const datatype constantName ; OR ► const datatype constantName = value ; ► Example ► const int x = 10 ; ► Here, 'x' is a integer constant with fixed value 10.
  • 31. Example Program #include<iostream.h> #include<conio.h> void main(){ int i = 9 ; const int x = 10 ; i = 15 ; x = 100 ; // creates an error cout<< “i=“<<i<<“n x=“<< x ; }
  • 32. Using '#define' preprocessor ► We can also create constants using '#define' preprocessor directive. When we create constant using this preprocessor directive it must be defined at the beginning of the program (because all the preprocessor directives must be written before the global declaration). ► We use the following syntax to create constant using '#define' preprocessor directive... ► #define CONSTANTNAME value ► Example ► #define PI 3.14 ► Here, PI is a constant with value 3.14
  • 33. Example Program #include<iostream.h> #include<conio.h> #define PI 3.14 void main(){ int r, area ; cout<<"Please enter the radius of circle : " ; cin>>r; area = PI * (r * r) ; cout<<"Area of the circle “<<area ; }
  • 34. C++ Expressions ► In any programming language, if we want to perform any calculation or to frame any condition etc., we use a set of symbols to perform the task. These set of symbols makes an expression. ► An expression is a collection of operators and operands that represents a specific value. ► In the above definition, an operator is a symbol that performs tasks like arithmetic operations, logical operations, and conditional operations, etc. ► Operands are the values on which the operators perform the task. ► Example: ► c=a+b