0% found this document useful (0 votes)
11 views15 pages

Week 1 Lecture 02

The document covers the basics of identifiers, keywords, and data types in C++. It explains the rules for naming identifiers, the distinction between standard and user-defined identifiers, and the concept of keywords in C++. Additionally, it details built-in data types, including int, bool, char, and floating-point types, as well as the definition and use of constants in C++.

Uploaded by

haroonali101325
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views15 pages

Week 1 Lecture 02

The document covers the basics of identifiers, keywords, and data types in C++. It explains the rules for naming identifiers, the distinction between standard and user-defined identifiers, and the concept of keywords in C++. Additionally, it details built-in data types, including int, bool, char, and floating-point types, as well as the definition and use of constants in C++.

Uploaded by

haroonali101325
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

LECTURE 02

Week 1
IDENTIFIER
■ The identifiers are the names used to represent variable, constants,
functions in the program.
Some important rules for identifier name are as follows:
• The first character must be an alphabetic or underscore (_).
• The identifier name must consist of only alphabetic characters, digits
or underscores.
• The reserve word cannot be used as identifier name.
• C++ is case sensitive
− NUMBER is not the same as number
TYPES OF IDENTIFIERS

1. Standard Identifiers
A type of identifier that has special meaning in C++ is known as standard
identifier.
Example:
cout and cin are examples of standard identifiers.
2. User-defined Identifiers
The type of identifier that is defined by the programmer to access
memory location is known as user-defined identifier.
Example:
Some examples are a, marks and age etc.
KEYWORDS IN C++

■ Keyword is a predefined or reserved word in C++ library with


a fixed meaning and used to perform an internal operation.
■ C++ Language supports more than 64 keywords.
■ Every Keyword exists in lower case letter like break, case,
const, continue, int etc
DATA TYPES IN C++
 The data type defines a set of values and a set of operations on those
values.
 The data and its type are defined before designing the actual program
used to process the data.
 The type of each data value is identified at the beginning of program
design.
 Each data type require different amount of memory.
BUILT-IN DATA TYPES IN C++

Apart from there, we also have void and bool data types.
BUILT-IN DATA TYPES

 Different compilers may allow different ranges of values.


int Data Type

 Examples:
-6728
0
78
+763
 Positive integers do not need a + sign
 No commas are used within an integer
 Commas are used for separating items in a list
bool Data Type

 bool type
− Two values: true and false
− Manipulate logical (Boolean) expressions
 true and false are called logical values
 bool, true, and false are reserved words
char Data Type

 The smallest integral data type


 Used for characters: letters, digits, and special symbols
 Each character is enclosed in single quotes
− 'A', 'a', '0', '*', '+', '$', '&'
 A blank space is a character and is written ' ', with a space left between
the single quotes
Floating-Point Data Types

 C++ uses scientific notation to represent real numbers (floating-point


notation)
Floating-Point Data Types (Continued)

− float: represents any real number


 Range: 3.4E-38 to 3.4E+38 (four bytes)
− double: represents any real number
 Range: 1.7E-308 to 1.7E+308 (eight bytes)
− On most newer compilers, data types double and long double are same
C++ PROGRAM TO SIZES OF DATA TYPES

#include<iostream>
using namespace std;

int main()
{
cout << "Size of char : " << sizeof(char) << " byte" << endl;
cout << "Size of int : " << sizeof(int) << " bytes" << endl;
cout << "Size of float : " << sizeof(float) << " bytes" <<endl;
cout << "Size of double : " << sizeof(double) << " bytes" << endl;

return 0;
}
CONSTANT IN C++

 It is identifier whose value cannot be changed at the execution time of


program.
 In general, constant can be used to represent as fixed values in a C++
program. Constants are classified into following types.
 Also known as Literals.
 If any single character is enclosed between single quotes ‘ ‘ known as
single character constant.
 If set of characters are enclosed between double quotes “ ” known as
string character constant.

You might also like