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)

Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
C++ data types
C++ data typesC++ data types
C++ data types
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programming
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
Function in c
Function in cFunction in c
Function in c
 
C functions
C functionsC functions
C functions
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and Associativity
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
C# Strings
C# StringsC# Strings
C# Strings
 
c-programming
c-programmingc-programming
c-programming
 
Loops c++
Loops c++Loops c++
Loops c++
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming 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
 
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
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingData Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingSherwin Banaag Sapin
 

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
 
Constants variables data_types
Constants variables data_typesConstants variables data_types
Constants variables data_types
 
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
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingData Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# Programming
 

Recently uploaded

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

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