C++ Tokens: Derived Data Types
C++ Tokens: Derived Data Types
Boolean or logical data type is a data type, having two values (usually denoted true and false), intended
to represent the truth values of logic and Boolean algebra. It is named after George Boole, who first
defined an algebraic system of logic in the mid 19th century. The Boolean data type is the primary result
of conditional statements, which allow different actions and change control flow depending on whether a
programmer-specified Boolean condition evaluates to true or false.
C99 added a Boolean (true/false) type which is defined in the <stdbool.h>
header Boolean variable is defined by kkey word bool; Ex:
bool b;
where b is a variable which can store true(1) of false (0)
Void type
The void type has no values. This is usually used to specify the return type of functions. The type of the function
said to be void when it does not return any value to the calling function. This is also used for declaring general
purpose pointer called void pointer.
Derived data types.
Derived datatypes are Arrays , pointer and references are examples for derived data types.
User-defined data types:
they The data types defined by the user are known as the user-defined data types.
They are structure,union,class and enumeration
C++ Tokens
IDENTIFIERS: Identifiers are the names given to various program elements such as variables, functions
and arrays. These are user defined names consisting of sequence of letters and digits.
Rules for declaring identifiers:
The first character must be an alphabet or underscore.
It must consist of only letters, digits and underscore.
Identifiers may have any length but only first 31 characters are significant.
It must not contain white space or blank space.
We should not use keywords as identifiers.
Upper and lower case letters are different.
Example: ab Ab aB AB are treated differently
Examples of valid identifiers:
a, x, n, num, SUM, fact, grand_total, sum_of_digits, sum1
Note: Some compilers of C recognize only the first 8 characters only; because of this they are unable
to distinguish identifiers with the words of length more than eight characters.
Variable declaration: The declaration of variable gives the name for memory location and its size and
specifies the range of value that can be stored in that location.
Syntax:
Data type variable name;
Ex: a 10 2000
int a=10;
float x=2.3; x 2.300000 5000
KEYWORDS :
There are certain words, called keywords (reserved words) that have a predefined meaning in
„C++‟ language. These keywords are only to be used for their intended purpose and not as identifiers.
The following table shows the standard „C++‟ keywords
auto break case char const continue
default do double else enum extern
float for goto if int long
register return short signed sizeof static
struct switch typedef union unsigned void
volatile while class friend new delete
this public private protected inline try
throw catch template
CONSTANTS:
Constants refer to values that do not change during the execution of a program.
Constants can be divided into two major categories:
1.Primary constants:
a)Numeric constants
Integer constants.
Floating-point (real)
constants. b)Character constants
Single character constants
String constants
2.Secondary constants:
Enumeration constants.
Symbolic constants.
Arrays, unions, etc.
Rules for declaring constants:
1.Commas and blank spaces are not permitted within the constant.
2.The constant can be preceded by minus (-) signed if required.
3.The value of a constant must be within its minimum bounds of its specified data type.
Integer constants: An integer constant is an integer-valued number. It consists of sequence
of digits. Integer constants can be written in three different number systems:
1.Decimal integer (base 10).
2.Octal integer (base 8).
3.Hexadecimal (base 16).
Decimal integer constant: It consists of set of digits, 0 to 9.
Valid declaration: 0, 124, -56, + 67, 4567 etc.
Invalid declaration: $245, 2.34, 34 345, 075.
23,345,00. it is also an invalid declaration.
Note: Embedded spaces, commas, characters, special symbols are not allowed between digits
They can be preceded by an optional + or ± sign.
The magnitude (maximum value) of an integer constant can range from zero
to some maximum value that varies from one computer to another.
Typical maximum values for most personal computers are: (16-bit machines)
Decimal integer constant: 32767 (215-1)
Octal integer constant: 077777
Hexadecimal integer constant: 0X7FFF
Note: The largest value that can be stored is machine dependent.
Floating point constants or Real constants : The numbers with fractional parts are called real constants.
These are the numbers with base-10 which contains either a decimal part or exponent (or
both). Representation: These numbers can be represented in either decimal notation or
exponent notation (scientific notation).
Decimal notation: 1234.56, 75.098, 0.0002, -0.00674 (valid notations)
Exponent or scientific notation:
General form: Mantissa e exponent
Mantissa: It is a real number expressed in decimal notation or an integer notation.
Exponent: It is an integer number with an optional plus (+) or minus (-) sign.
E or e: The letter separating the mantissa and decimal part.
Ex: (Valid notations)
3
1.23456E+3 (1.23456×10 )
1
7.5098 e+1 (7.5098×10 )
-4
2E-4 (2×10 )
These exponential notations are useful for representing numbers that are either very large or very
small. Ex: 0.00000000987 is equivalent to 9.87e-9
Character constants:-
Single character constants: It is character(or any symbol or digit) enclosed within single quotes.
Ex: „a‟ „1‟ „*‟
Every Character constants have integer values known as ASCII values
ASCII:- ASCII stands for American Standard Code for Information Interchange. Pronounced ask-ee, ASCII is a
code for representing English characters as numbers, with each letter assigned a number from 0 to 255.Computers
can only understand numbers, so an ASCII code is the numerical representation of a character such as 'a' or '@' or an