data types

Post on 13-Jan-2017

36 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

DATA TYPES

Data type is defined as a set of values and a set of operations.

For example, the set of all integer (whole) numbers constitutes a set of values.

This set of numbers, however, doesn’t constitute a data type until a set of operations is included.

These operations, of course, are the familiar mathematical and comparison operations. The combination of a set of values plus operations results in a true data type.

A class data type (referred to as a “class,” for short) is a programmer-created data type.

A built-in data type is provided as an integral part of the programming language. Built-in data types are also referred to as primitive types.

A literal value means the value identifies itself or constant. For example, all numbers, such as 2, 3.6, and -8.2, are referred to as literal values because they literally display their values.

Text, such as “Hello World!”, is also referred to as a literal value because the text itself is displayed.

Integer Data Types

C++ provides nine built-in integer data typesThe int Data Type The values supported by the int data type are whole numbers, which are mathematically known as integers.

Integer Data Types

An integer value consists of digits only and can optionally be preceded by a plus (+) or minus (-) sign. Therefore, an integer value can be the number 0 or any positive or negative number without a decimal point.

Integer Data Types

The following are the examples of valid integers

Integer Data Types

Examples show, integers can contain an explicit sign. However, no commas, decimal points, or special symbols, such as the dollar sign are not allowed, as in these examples of invalid integers:

The Escape Character

(\) has a special meaning in C++ as the escape character. When a backslash is placed in front of a group of characters, it tells the compiler to escape from the way these characters are normally interpreted.

top related