Topic 3 - Formatted Input/Output Flashcards

1
Q

What is a conversion specification?

A

A placeholder.

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

What is %d used for

A

int values as a conversion specifier

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

What is %f used for

A

float values as a conversion specifier

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

Too many conversion specifications _____ produce meaningless output.

A

will

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

Too few conversion specifications _____ produce meaningless output

A

might

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

Incorrect specification ____ produce meaningless output

A

will

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

In the conversion specification form: %m.pX (or %-m.pX) - what is m?

A

minimum field width - specifies the minimum number of characters to print

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

What happens when the value to be printed requires fewer than m characters?

A

It will be right-justified within the field and space characters will be inserted to its left

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

What does putting a minis sign in front of m do?

A

causes left justification in the event that the value to be printed requires fewer than m characters. Space characters are then inserted to the right of the value instead.

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

What happens if the value to be printed requires more than m characters?

A

the field with automatically expands to the necessary size.

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

The main of p in %m.pX depends on what.

A

The choice of X, the conversion specifier.

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

What does “p” indicate for %d specifier?

A

The minimum number of digits to be displayed - extra zeros are added to the beginning of the number, if necessary

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

If p is omitted with %d, what happens.

A

P is assumed to be 1.

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

What does p indicate for %f?

%e?

A

%f - fixed decimal format - p indicates the number of digits after the decimal point
%e - exponential format - p as the same meaning as for the f specified

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

What does p indicate for %g?

A

%g - either exponential format or fixed decimal format, depending on the number to b printed - e format is selected in case of too small numbers

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

Does the %g conversion show trailing zeros?

A

No

17
Q

If the number has no digits after the decimal point, does g display the decimal point?

A

No.

18
Q

What does scanf do when it arrives at the final new-line?

A

It “peeks” at the final new-line without reading it.

19
Q

How does scanf work when asked to read an integer?

A
  • first looks for a plus / minus sign (optional), followed by
  • digits
  • it then reads digits until it reaches a non-digit
20
Q

How does scanf work when asked to read a floating-point number?

A
  • looks for plus or minus sign (optional)
  • followed by digits (possibly containing a decimal point)
  • it then reads digits until it reaches a non-digit
21
Q

What happens when scanf encounters a character that can’t be part of the current item?

A

The character is “put back” to be read again during the scanning of the next input item

22
Q

Scanf’s format string capabilities:
If the format string is “%d/%d” and the input is •5/•96¤
Does it fail or succeed?

A

The / from the input matches the / in the format string in the scanf’s arguments so it succeeds.

23
Q

If the format string is “%d/%d” and the input is •5•/•96¤

Does it fail or succeed/

A

the “ / “ has a space character before the “/” that does not match the format string

24
Q

If the format string is
“%d / %d” and the input is”
If the format string is “%d/%d” and the input is
•5/•96¤

5/96¤

•5•••••/•••••••96¤



96¤

A
  • succeed
  • succeed
  • succeed
  • succeed