2. Levels of Programming Languages
There are 3 levels of programming
languages
i) High-Level Language
ii) Middle-Level Language
iii) Low-Level Language
2
3. Uses of C/C++ Programming Language
Areas where C/C++ language can be used are
Operating Systems
Network Drivers
Communication Packages
Databases
Language Interpreters
Utilities
Language Compilers
Spreadsheets
Text Editors
etc etc
3
4. C/C++ Character Set
C/C++ character set comprises of
following characters
A,B,C,….Z
a,b,c,…...z
0,1,2,……9
, . ; : ? ! “ / ‘ | ~
( ) [ ] { } < >
+ - # % _ ^ = & *
4
5. White Space Characters
The character that produces blank
space when printed is called a white
space character, e.g.
Spaces
Tabs
New Lines
5
6. Data Transformation
Programs transform data from one form to another
Input data Output data
Stimulus Response
Programming languages store and process data in
various ways depending on the type of the data;
consequently, all data read, processed, or written
by a program must have a data type
Two distinguishing characteristics of a programming
language are the data types it supports and the
operations on those data types
6
7. 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)
9. 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:-
Date Type Used for Examples
String
Alphanumeric
characters
“hello world”, “Islamabad”,
“Alice”
Integer Whole numbers 7, 12, 999, -47
Float (floating
point)
Number with a decimal
point
3.15, 9.06, 00.13
Character
Single alphabet or
number
‘A’, ‘9’, ‘&’ (uses ASCII)
Boolean
Representing logical
values
True, False
10. A Data Type
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
11. A Data Type (continued)
When the compiler encounters a declaration for
a variable, it sets up a memory location for it
An operator used on a variable or variables is
legal only if
The operator is defined in that programming
language for a variable of that type
The variable or variables involved with the
operator are of the same or compatible
types
11
13. 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
14. Primitive Built-in Data Types
Many of the above data types can be modify
using these modifiers:-
signed
unsigned
short
long
15. Variable Types and Memory Used
Type
Typical Size
(Byte)
Typical Range
char 1 byte -128 to 127
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
int 4 bytes
-2147483648 to
2147483647
unsigned int 4 bytes 0 to 4294967295
signed int 4 bytes
-2147483648 to
2147483647
16. Variable Types and Memory Used
Type
Typical Size
(Byte)
Typical Range
short int 2 bytes -32768 to 32767
unsigned short int 2 bytes 0 to 65,535
signed short int 2 bytes -32768 to 32767
long int 8 bytes
-
9,223,372,036,854,775,808
to
9,223,372,036,854,775,807
signed long int 8 bytes
-
9,223,372,036,854,775,808
to
9,223,372,036,854,775,807
unsigned long int 8 bytes
0 to
18,446,744,073,709,551,61
5
17. Variable Types and Memory Used
Type
Typical Size
(Byte)
Typical Range
float 4 bytes
-3.4 x 1038 to +3.4 x 1038
(~7 digits)
double 8 bytes
-1.7 x 10308 to +1.7 x 10308
(~15 digits)
wchar_t 2 or 4 bytes 1 wide character
18. 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
19. 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
21. 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
22. 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
23. 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