By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,782 Members | 1,154 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,782 IT Pros & Developers. It's quick & easy.

How well did I do??? Quiz 3

P: n/a
DJ
Here are my answers for quiz 3 - how well did I do?
1. If the statement:

scanf("%d %d", &N1, &N2);

returns the value 1, what do we know about what was read into the variables
N1 and N2?

a. Both values were read successfully.

b. N1 was successfully read, but not N2.

c. N2 was successfully read, but not N1.

d. Neither value was read successfully.

A

2. Which of the following must be done before any other operations can be
performed on a file (other than stdin, stdout and stderr)?

a. fseek

b. fopen

c. fgets

d. rewind

B

3. During file processing, a file is referenced via what type of variable?

a. A file handle (type int).

b. A file pointer (type FILE *).

c. The file name (type char[ ]).

d. A pointer to the file name (typechar *).

B

4. If a file is opened for writing or appending and the file does not exist,
what action is taken:

a. A new file is created.

b. An error message is issued.

c. A NULL value is returned.

d. An EOF value is returned.

A

5. Choose the printf statement that will print the number X in floating
point notation, in a field of 10 characters with 3 characters to the right
of the decimal point.

a. printf("%10.3e", X);

b. printf("%3.10f", X);

c. printf("%10.3f", X);

d. printf("10.3%f", X);

C

6. If a file is opened for reading and the file does not exist, what action
is taken?

a. A new file is created.

b. A NULL value is returned.

c. An error message is issued.

d. An EOF value is returned.

C

7. Choose the scanf statement that will read in a date in the form mm/dd/yy
into three integer variables Month, Day and Year. The /characters should be
matched and skipped over by the scanf.

a. scanf("%1d/%1d/%1d", &Month, &Day, &Year);

b. scanf("%*d/%*d/%*d", &Month, &Day, &Year);

c. scanf("%d %d %d", &Month, &Day, &Year);

d. scanf("%d/%d/%d", &Month, &Day, &Year);

D

8. If you need to display a listing of the current directory from within a C
program, the best way to do it is:

a. include the header file which describes directory files.

b. open the directory as an ordinary file and use scanf and printf.

c. use the system function and the appropriate operating system command.

d. It is not possible to access a directory from within a C program.

C

9. Which of the following would typically be found as environment variables?

a. Base directory name

b. Total processor time used by a program

c. A list of names and phone numbers

d. All of the above

A

10. The archiver or librarian utility is used to:

a. combine group of small files into a single file.

b. automatically recompile .c files as necessary.

c. keep track of changes to a program.

d. All of the above.

A

11. If we want the random number library function to produce a different
sequence of values each time the program is run which of the following
statements should be used?

a. setenv(rand());

b. fopen(srand());

c. srand(clock());

d. srand(time(NULL));

C

12. The C statement which will execute the system command logout from within
a program is:

a. printf("logout");

b. system("logout");

c. setenv(logout);

d. system(logout);

B

13. The difference between stream output and printf is:

a. type and formatting information is not used with stream I/O.

b. stream I/O can be directed to any output device.

c. stream I/O is faster.

d. printf cannot be used in C++.

C

14. The difference between a class and a structure is:

a. classes can be printed using stream I/O.

b. classes can be overloaded.

c. classes include functions to perform operations.

d. classes can be inherited.

D

15. What is the purpose of a constructor?

a. to declare a new class.

b. to copy a new value into a string.

c. to initialize an object.

d. to define macros with arguments.

C

16. Choose the C++ statement which is equivalent to:

printf("Area = %g \n", PI * Radius * Radius);

a. cout >> "Area = " >> PI * Radius * Radius >> endl;

b. cout << "Area = " << PI * Radius * Radius << endl

c. cout << "Area = " << PI * Radius * Radius;

d. cout << "Area = " << PI * Radius * Radius << endl;

D

17. In C++, int f() is equivalent to:

a. int f(void) in ANSI C

b. int f() in traditional C

c. Both a and b.

d. None of the above.

C

18. The private members of a class:

a. can only be referenced with the block where the class is defined.

b. cannot be modified.

c. can only be referenced by member functions of the same class.

d. can only be referenced by member functions of the class or by friend
functions.

D

19. An #include file will usually contain:

a. constants defined with #define.

b. function prototypes.

c. type definitions.

d. All of the above.

D

20. Macros are expanded:

a. just before the program is compiled.

b. concurrently with the program compilation.

c. just after the program is compiled.

d. just before the program is loaded into memory and executed.

B

21. The most common reason for using a macro instead of a function is:

a. to save storage space.

b. to reduce the possibility of errors.

c. to make the program run faster.

d. All of the above.

C

22. In order to include a header file which is in your current directory,
use which of the following ?

a. #include <filename>

b. #include "filename"

c. #include filename

d. All of the above could be used.

B

23. Which of the following is a valid macro definition to generate the
square of a number?

a. #define SQUARE(X) = ((X(*(X));

b. #define SQUARE(float X) = ((X)*(X))

c. #define SQUARE(X) + ((#X)*(#X))

d. #define SQUARE(X) ((X)*(X))

D

24. Choose the INCORRECT statement.

a. Macro arguments are evaluated each time they appear in the macro
definition; arguments with side effects can cause unexpected results due to
multiple evaluations.

b. Macro code is inserted into the program each time the macro name is used,
thereby making the program larger.

c. When defining a macro, there can be white space between the opening
parenthesis and the macro name.

d. Macro arguments are evaluated in the context of any surrounding
expressions; unless parenthesized, the precedence of adjacent operators can
cause unexpected results.

C

25. How will the preprocessor expand the following code?

#define USEFLOAT 0

int N;

#if USEFLOAT

float X;

#else

double X;

#endif

a. int N;

b. int N;

double X;

c. int N;

float X;

d. none of the above

B
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
DJ wrote:
Here are my answers for quiz 3 - how well did I do?


You made 5 mistakes (IMHO).
Apart from that, Q14 and Q16 are wrong (they should be
"None of the above"), Q9 and Q21 are offtopic, and Q20
is unclear (the correct answer according to the C++ standard
is B, but I suspect they are looking for A).

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.