Topic 7 - Basic Types Flashcards

1
Q

The leftmost bit of a SIGNED integer is:

A

0 if number is positive or zero

1 if number is negative

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

The largest 16-bit signed integer is:

A

2^15 - 1

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

The largest 32-bit signed integer is:

A

2^31 - 1

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

An integer with no sign bit is said to be:

A

unsigned

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

largest 16 bit unsigned integer is:

A

2^16 - 1

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

largest 32 bit unsigned integer is:

A

2^32 - 1

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

By default, what type of integers are integer variables?

A

Signed integers.

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

How many bits is the int type usually?

A

32 bits

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

How do you tell the compiler that a variable has no sign bit?

A

declare it as unsigned.

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

Decimal constants contain digits between___ and

must / must not begin with___

A

0 and 9

must not begin with a zero

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

Octal constants contain digits between___ and

must / must not begin with___

A

0 and 7

must begin with a zero

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

Hexadecimal constants contain digits between___ and

letters between a and f must begin with ___

A
0 and 9
0x or 0X:
0xf
0xff
0X7fff
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The letters in a hexadecimal constant may be _____

A

either upper or lower case

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

How do you force the compiler to treat a constant as a long integer?

A

with the letter L or l:
15L
0x7fffL

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

How do you force the compiler to treat a constant as an unsigned integer?

A

follow it with the letter U or u:
15U
0x7fffU

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

What is the term that describes the event where arithmetic operations performed on integers results in a number too large to be represented as an int( because it requires too many bits)?

A

Overflow

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

How do you read or write an unsigned decimal integer? (ie. when using scanf or printf)?

A

Use the letter “u” instead of “d” as a conversion specifier.

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

How do you read or write an unsigned octal integer? (ie. when using scanf or printf)?

A

“o” instead of “d”

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

How do you read or write an unsigned hexadecimal integer? (ie. when using scanf or printf)?

A

“x” instead of “d”

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

How do you read or write a short integer? (ie. when using scanf or printf)?

A

“h” in front of d, u, o, x in the conversion specification:

scanf(“%hd”, &i);

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

How do you read or write a long integer? (ie. when using scanf or printf)?

A

“l” (letter L) in front of d, u, o, or x in the conversion specification:
scanf(“%ld”, &i);

22
Q

C provides how many floating types?

A

3 types

23
Q

What are the types of floating types?

A

float - single-precision floating-point
double - double-precision floating-point
long double - extended-precision floating-point

24
Q

State the usefulness of each of the floating types:

A

float - suitable when the amount of precision is not critical
double - provides enough precision for most programs
long double - rarely used

25
Q

What does C standard state on how much precision the 3 types have?

A

C standard does not state how much precision the float, double and long double types provide, since that depends on how numbers are stored.

26
Q

What is the 2 primary formats for floating-point numbers in IEE standard 765:

A

1) single-precision (32 bits)

2) double-precision (64 bits)

27
Q

How are numbers stored when stored as a floating point??

A

number = sign x fraction x 2^exponent

28
Q

Single-precision format: how many bits long?

A

exponent: 8 bits
fraction: 23 bits

29
Q

double-precision format: how many bits long?

A

exponent: 11 bits
fraction: 52 bits

30
Q

By default, floating constants are stored as?

A

double-precision numbers

31
Q

How do you indicate that only single precision is desired when storing a constant?

A

put the letter f or F at the end of the constant ie. 57.9F

32
Q

A floating constant must contain:

A

a decimal point or an exponent (or both)

33
Q

What are the conversion specifiers %e, %f and %g’s precision?

A

Used to read/write single-precision.

34
Q

How do you force read a value of type double?

A

put an “l” in front of f or e or g:

scanf(“%lf”, &d);

35
Q

How many bytes does a char consume?

A

A single byte.

36
Q

Signed characters have values between:

A

-128 and 127

37
Q

Unsigned characters have values between:

A

0 and 255

38
Q

What function can you use to convert a character to its upper-case counterpart?

A
#include 
ch = toupper(ch)
39
Q

What’s the conversion specification for scanf and printf to read and write single characters:

A

“%c”

40
Q

Does scanf skip white-space characters as usual when reading %c?

A

No

41
Q

How do you force scanf to skip white-space characters?

A

put a space in its format string before the %c:

scanf(“ %c”, &ch);

42
Q

For reading and writing a single character, what is an alternative function to scanf/printf?

A

putchar and getchar:
putchar(ch);
ch = getchar();

43
Q

Does getchar skip white-spaces?

A

No

44
Q

Write a statement that uses getchar to skip an indefinite number of blank characters

A

while ((ch = getchar()) == ‘ ‘)
;
when the loop terminates, the ch will contain the first nonblank character that getchar encountered

45
Q

What are the requirements of the two operands to perform an arithmetic operation?

A

They must be the same size ie. same number of bits.

Stores in the same way.

46
Q

What is an implicit conversion?

A

When the compiler matches the types of 2 operands that are having arithmetic or logical operations being performed on them - the smaller sized type gets casted to the 2nd operand’s type so precision isn’t lost

47
Q

What are the 4 cases in which implicit conversion is carried out by the compiler?

A

1) unmatched operands in an arithmetic or logical operation
2) assignment type mismatch with variable type
3) input type mismatch with function’s argument type
4) return statement returning value of mismatched type with argument’s return type

48
Q

What are the 2 cases for performing the usual arithmetic conversions?

A

1) the type of other operand is a floating type

2) neither operand type is a floating type

49
Q

Can you force implicit conversions?

A

Yes.

50
Q

What does C regard ( type-name) as?

A

A unary operator (which has higher precedence than binary operators)

51
Q

What type is returned by sizeof operator?

A

An unsigned integer representing the number of bytes required to store a value belonging to type-name