Professional Documents
Culture Documents
Language Datatypes
Lecture 5
1
Levels of Programming Languages
There are 3 levels of programming
languages
i) High-Level Language
ii) Middle-Level Language
iii) Low-Level Language
2
Uses of C/C++ Programming Language
3
C/C++ Character Set
0,1,2,……9
, . ; : ? ! “ / ‘ \ | ~
( ) [ ] { } < >
+ - # % _ ^ = & *
4
White Space Characters
5
Data Transformation
Programs transform data from one form to another
Input data Output data
Stimulus Response
6
Data Handling
Various types of data
E.g. letters, numbers, symbols, etc.
Data handling requires different data types
Data Type: type of data that a variable can
hold and the operations that can be
performed on it.
Logical to ask the computer to multiply a
float by an integer (1.5 x 5)
Illogical to ask the computer to multiply a
float by a string (1.5 x FUI)
Constants & Variables
Constants
1, 56, 1.89, ’a’, ’Z’, ”BSSE”
Variables
x=5
y = 20
8
What is Data Type
A data type is a set of values, together with a set of
associated operations on those values.
Here is the table for different types:-
A data type is
A set of values AND
A set of operations on those values
A data type is used to
Identify the type of a variable when the
variable is declared
Identify the type of the return value of a
function
Identify the type of a parameter expected
by a function
10
A Data Type (continued)
11
C++ Data Types
Primitive Built-in Data Types
Type Keyword
Boolean bool
Character char
Integer int
Floating point float
Double floating point double
Valueless void
Wide character wchar_t
Primitive Built-in Data Types
Many of the above data types can be modify
using these modifiers:-
signed
unsigned
short
long
Variable Types and Memory Used
Typical Size
Type Typical Range
(Byte)
char 1 byte -128 to 127
Typical Size
Type Typical Range
(Byte)
-3.4 x 1038 to +3.4 x 1038
float 4 bytes
(~7 digits)
-1.7 x 10308 to +1.7 x 10308
double 8 bytes
(~15 digits)
wchar_t 2 or 4 bytes 1 wide character
Data Types
Boolean: for storing true or false values.
Boolean variables are declared using the
keyword bool
String: generally means an ordered
sequence of characters, enclosing
delimiters are double quotes “some string“.
Declared using keyword string
The sizes of variables might be different
from those shown in the above table,
depending on the compiler and the
computer you are using.
18
Variable Declaration
When variables are declared of a
particular data type then
the variable becomes the place where the data is
stored, and
data types is the type of value(data) stored by
that variable.
int var;
int is the datatype of the variable,
var is the variable name
; is statement terminator
Identifiers
Identifiers refer to the names of
data types, constants, variables, and
functions
Cannot be keywords
20
Rules for Constructing Identifiers in C++
Can contain letters, digits and underscores,
capital letters A-Z, lowercase letters a-z,
digits 0-9, and the underscore character _
Digit can not be the first character.
First character must be a letter or
underscore
Can not consist of an underscore alone.
Usually only the first 32 characters are
significant.
21
Rules for Constructing Identifiers in C++
(contd.)
May not be same as keyword or function
name etc.
There can be no embedded blanks (spaces
are not allowed).
Keywords cannot be used as identifiers
Identifiers are case sensitive
22
Types of C/C++ Instructions
There are 4 types of C/C++ Instructions.
i) Type declaration Instructions
Variable types and definitions etc.
ii) Input/Output Instructions
Data Input, Data Display, Data
Write etc
iii) Control Instructions
Controls the sequence of execution
of the program instructions.
iv) Arithmetic Instructions
Arithmetic Operations etc
23