Fundamental Data Types Flashcards

1
Q

What does the data type tell the compiler?

A

How much memory to set aside for a variable and how to interpret the bits/bytes at a memory address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the syntax for explicit vs. implicit assignment

A

Explicit:
type varName = value;

Implicit:
type varName(value);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Is the following syntax correct or incorrect:

int nValue 1, int nValue2;

A

Incorrect; this will not compile b/c only one type can be specified per line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

T/F: In the following expression the value of ‘nValue 1’ is 5:

int nValue1, nValue2 = 5;

A

F; nValue 2 contains the value 5, whereas nValue1 is uninitialized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a keyword in C++?

A

An identifier reserved by the language that cannot be reused

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an identifier?

A

The name of a function, variable, class, or any entity in C++

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the rules for creating an identifier?

A

It cannot be a keyword, must be composed only of letters, numbers, and the underscore character, must begin with a letter or underscore (not a number), is case sensitive, and describes the thing that it identifies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Hungarian notation?

A
prefixing a variable with an indication of its type:
int nValue;
bool bValue;
char chValue;
double dValue;
float fValue;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How is memory assigned to a variable with a size larger than 1 byte?

A

Consecutive memory addresses are used

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the ‘sizeof()’ operator?

A

It is a unary operator which returns the size of a type or variable in bytes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

T/F: The size of data types is not consistent across systems

A

T; The size of any data type is not guaranteed to be a specific value on any given system, although it will likely be close.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the four types of integers and their approximate sizes?

A

char (1 byte)
short (2 bytes)
int (2 or 4 bytes)
long (4 bytes)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

T/F: ‘short’ and ‘long’ are shorthand

A

T; they stand for ‘short int’ and ‘long int’, respectively

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does the signed/unsigned qualification affect the range of an integer?

A

Unsigned integers cannot store negative values, but can store positive numbers that are twice as large as those stored by a signed integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the definition of an integer?

A

A data type which holds whole numbers/characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Are all integers signed or unsigned by default?

A

signed, but the compiler is smart enough to know to use signed or unsigned if it sees a negative number (the ‘-‘ unary operator)

17
Q

What is overflow and what happens when it occurs?

A

Overflow occurs when a value outside of a data type’s range is attempted to be placed in a variable of that data type. In overflow bits are lost, and the value ‘wraps around’ back to the opposite end of its range.

18
Q

What will 65536 and 65537 overflow to for an int type (max 4 bytes)?

A

0 and 1, respectively, the two bit patterns are 1 0000 0000 0000 0000 and 1 0000 0000 0000 0001. In both cases the bits greater than the 4 bytes available are lost, meaning that the two values become 0000 0000 0000 0000 and 0000 0000 0000 0001. This is why the values ‘wrap around’. Note that the same thing happens in reverse if the lower limit of the values is exceeded.

19
Q

Why is overflow such a bad thing?

A

It results in information being lost

20
Q

What are the three floating point types and their approximate sizes?

A
float (4 bytes)
double (8 bytes)
long double (>8 bytes)
21
Q

What does the float in “floating point” refer to?

A

The ‘float’ in floating point refers to the fact that a floating point number can have a variable number of decimal places.

22
Q

How are floats represented in memory?

A

Floats are represented in memory in a manner not unlike scientific notation, with the significand and its exponent.

23
Q

What is the precision of a floating point number?

A

How many digits it can represent without information loss.

24
Q

What can be done to change the default precision of functions like ‘cout’?

A

Use the function setprecision(int)

25
Q

What are floating points extremely succeptible to?

A

rounding errors

26
Q

What is the convention for methods that return a boolean?

A

name the method starting with ‘Is’; IsEqual, IsTrue, etc.

27
Q

T/F: any integer <= 0 will evaluate to false when cast as a bool

A

F; 0 is the only value that becomes false when cast as a bool; all other values evaluate to true.

28
Q

T/F: The following statements are equivalent:
char chValue = ‘a’;
char chValue2 = 97;

A

T; 97 is the ASCII code for ‘a’

29
Q

T/F: The compiler will not know what to do with the following statement and will produce an error:
char chChar = 97;

A

F; The compiler merely assignes the ASCII character code 97 to ‘chChar’, and when out put by a function like ‘cout’ it will yield ‘a’

30
Q

What happens when a string or array of chars is placed into a char variable?

A

Overflow; only the first char is assigned, the other chars are lost.

31
Q

What is a literal constant, and what are some examples?

A

Literal constants are literal numbers inserted into the code. They are constants because you can’t change their values. Examples are integer and float values.

32
Q

T/F: Floating point literal constants are of type double by default

A

T, add an ‘l’ or ‘L’ to the end to make it a long double, or an ‘f’ to make it a float.

33
Q

What are the two major problems with symbolic constants made with #define?

A

They do not show up in the debugger, and they have global scope.

34
Q

What is the best way to declare symbolic constants?

A

With the ‘const’ keyword before the type

35
Q

What are two pros of Hungarian notation?

A

It removes type ambiguity and can shorten variable names

36
Q

What is the typical syntax for Hungarian notation?

A

_varName

int* pnValue;
int nValue;
const int g_nGlobalValue;