C++ Data Types

Ace your homework & exams now with Quizwiz!

What is the minimal range for the data type unsigned char ?

unsigned char: 0 to 255

What is the minimal range for the data type unsigned int ?

unsigned int: 0 to 65,325

What is the minimal range for the data type unsigned long int ?

unsigned long int: 0 to 4,294,967,295

What is the minimal range for the data type unsigned short int ?

unsigned short int: 0 to 65,325

What modifiers can be applied to char?

The 2 modifiers signed, unsigned can be assigned to char.

What is the minimal range for the data type char ?

char: -127 to 127. So char actually stores numbers which represent the standard character set (like on a computer keyboard). A is represented by the value 65, B by 66, C by 67 and so on. Each character in the set is represented by a different number. The character set is referred to as ASCII (American Standard Code for Information Interchange).

How can you explicitly convert types ?

(type) expression explicitly forces a conversion e.g. (float) x / 2 makes sure the expression is evaluated to type float

What are the arithmetic operators

+ - * / % (modulus) ++ (increment) -- (decrement)

What are the relational operators

> >= < <= == (equal to) != (not equal to)

What are data type modifiers ?

A modifier alters the meaning of the base data type so that it more precisely fits the needs of the various situations.

What modifiers can be applied to double?

The modifier long can be assigned to double.

What is the minimal range for the data type int ?

int: -32,767 to 32,767

What is the minimal range for the data type long int ?

long int: -2,147,483,647 to 2,147,483,647

Give an example of Type conversion

short a=2000; int b; b=a; In this example the value of a is promoted from short to int without the need of any explicit operator. There is no problem because b (int) can take the value of a. There might be a problem in trying to assign the value of b (int) into a (short)

What is the minimal range for the data type short int ?

short int: -32,767 to 32,767

What are the rules for Type Conversion in assignments.

= is the assignment operator. It works as var = expression; When variables of one type are mixed with variables of another type, a type conversion occurs. In assignments, the rule is simple - the value of the right side of the assignment (expression) is converted to the type of the left side (target variable) eg int x; float f = 5.654321; x = f; because it is an integer, x is assigned the nonfractional part of f i.e. 5. There would be no problem (loss of information) going the other way e.g. float f; int x = 5; f = x; f would receive the value 5 and store it as 5.000000

What are literals

Literals refer to fixed, human-readable values that cannot be altered by the program. They are commonly referred to as constants.

Why does C++ have different data types for integers and floating-point values?

So you can write efficient programs. E.g. integer arithmetic is faster than floating-point calculations. This if you don't need fractional values, then you don't need to incur the overhead associated with types float or double. In a small sample program this may not seem much but in a large complex program, or one that is used by millions of people, the small efficiencies add up. Also, the amount of memory required for one type of data might be less than that required for another. Thus you can make best use of system resources.

What are the 4 data type modifiers ?

The 4 data type modifiers are: signed; unsigned; long; short.

What modifiers can be applied to int?

The 4 modifiers signed, unsigned, long, short can be assigned to int.

What are the 7 Data Types?

The 7 Data Types are: char (Character); wchar_t (Wide character); int (Integer); float (Floating point); double (Double floating point); bool (Boolean); void (Valuless).

Why are data types important

The data type of a variable is important because it determines the operations that are allowed and the range of values that can be stored. E.g. you can multiply 3 * 6 but not three * six. Because data types differ, all variables must be declared prior to their use, and a variable declaration always includes a type specifier. The compiler requires this to generate correct code. Also, several of the basic types are closely tied to the building blocks upon which the computer operates bytes and words. This helps you write efficient code.

What are the rules for Type Conversion in Expressions

When constants and variables of different types are mixed in an expression, they are temporarily converted to the same type. They are 'promoted'. E.g. char and short int are automatically elevated to int. Next operands are converted 'up' to the type of the largest operand. E.g. if one operand is an int and the other is a long int, then the int is promoted to a long int. Once a conversion has been applied, each pair of operands will be of the same type and the result of each operation will be the same as the type of both operands.

Define variable

a portion of memory to store a value. Each variable needs a name that identifies it (an identifier) and distinguishes it from the others. A valid identifier is a sequence of one or more letters, digits, or underscore characters (_). Spaces, punctuation marks, and symbols cannot be part of an identifier. In addition, identifiers shall always begin with a letter. Identifiers may not be the same as the C++ keywords. C++ is case sensitive. Thus, for example, the RESULT variable is not the same as the result variable or the Result variable.

What is the minimal range for the data type double ?

double: 1E-37 to 1E+37, with 10 digits of precision

What is the minimal range for the data type long double ?

double: 1E-37 to 1E+37, with 10 digits of precision

What is the minimal range for the data type float ?

float: 1E-37 to 1E+37, with 6 digits of precision

What is the minimal range for the data type signed char ?

signed char -127 to 127

What is the minimal range for the data type signed int ?

signed int: same as int i.e. -32,767 to 32,767

What is the range for the data type signed long int ?

signed long int: same as long int i.e. -2,147,483,647 to 2,147,483,647

What is the minimal range for the data type signed short int ?

signed short int: same as short int i.e. -32,767 to 32,767

Type conversion with booleans

values of type bool are automatically converted to the integers 0 (false) or 1 (true)

What are the logical operators

&& (AND) || (OR) ! (NOT)


Related study sets

Organic Chemistry Timberlake Chapter 11 & 12

View Set

Unit 6: Panic Anxiety and Their Disorders

View Set

Electrical Code Calculations Lv2 - NEC 2017

View Set

US History Unit 7: New Deal Programs

View Set