0% found this document useful (0 votes)
29 views

C++ Tokens: Derived Data Types

1) Boolean data type represents logical true and false values and is defined as true/false in C99. 2) Variables are named memory locations used to store values of a particular data type. 3) Keywords are predefined words in C++ that have special meaning and cannot be used as identifiers.

Uploaded by

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

C++ Tokens: Derived Data Types

1) Boolean data type represents logical true and false values and is defined as true/false in C99. 2) Variables are named memory locations used to store values of a particular data type. 3) Keywords are predefined words in C++ that have special meaning and cannot be used as identifiers.

Uploaded by

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

Boolean data type:-

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

Examples of Invalid identifiers: $amount, ³num´, grand-total, sum of digits, 4num.


$amount : Special character is not permitted
grand-total : hyphen is not permitted.
sum of digits : blank spaces between the words are not allowed.
4num : should not start with a number (first character must be a letter or underscore

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.

Variables:A named memory location is called variable.


OR
It is an identifier used to store the value of particular data type in the memory.
Since variable name is identifier we use following rules which are same as of identifier
Rules for declaring Variables names:
  
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.

Variable names must be unique in the given scope
 
Ex:int a,b,a;//is in valid
Int a,b;//is valid

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.

Octal integer: It consists of set of digits, 0 to 7.


Ex: 037, 0, 0765, 05557 etc. (valid representation)
It is a sequence of digits preceded by 0.
Ex: Invalid representations
0394: digit 9 is not permitted (digits 0 to 7 only)
235: does not begin with 0. (Leading number must be 0).

Hexadecimal integer: It consists of set of digits, 0 to 9 and alphabets A, B, C, D, E,


and F. Hexadecimal integer is a sequence of digits preceded by 0x or 0X. We can also
use a through f instead of A to F.
Ex: 0X2, 0x9F, 0Xbcd, 0x0, 0x1. (Valid representations)
Ex: Invalid representations: 0af, 0xb3g, 0Xgh.
0af: does not begin with 0x or 0X.
0xb3g, 0Xgh: illegal characters like g, h. (only a to f are allowed)

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy