COMP370 Practice for Exam 1

Instructions: There are 30 questions on this test. It is written in a style very similar to the REAL exam 1. Choose the best answer from among those given. Click the GRADE button on the bottom of the form when you want the exam graded.

Note: You can practice this test as many times as you desire; the system will cook you up a fresh batch of questions each time you access this page.

Your Name: @ 3.145.143.239

1. According to the way "MyFunct" is being used below, what is its prototype?

int x,y;
float z;
//
//Program logic to fill x and y with data here
//

z=MyFunct(x, y);

a) void MyFunct(int, int);
b) double MyFunct(double, int);
c) float MyFunct(int, int);
d) None of these

2. What is the effect of the break statement?

a) The body of a running loop is repeated
b) A running loop is exited, execution resumes at next statement after loop
c) The loop counter is decremented by 1
d) None of the above

3. What library function should be used to compare character string arrays?

a) strcat
b) strlen
c) strcmp
d) None of these

4. What is meant by the term "dereferencing?"

a) Finding the master inertial frame of reference
b) Accessing the memory contents addressed by a pointer
c) Finding the memory address of a value
d) None of the above

5. If A=4 upon entry into the code below, what will be output?

switch (a)
     {
     case 1: printf("Unlocking door.");
         break;

     case 2: printf("Checking back door.");
         break;

     case 3: printf("Locking door.");
         break;

     default: printf("Unknown command.");
         break;
     }

a) Checking back door
b) Unlocking door
c) Locking door
d) Unknown command

6. Which of these lists the fundamental data types of the C language in correct order of precision?

a) INT - CHAR - FLOAT - LONG INT - DOUBLE
b) INT - CHAR - DOUBLE - LONG INT - FLOAT
c) FLOAT - CHAR - INT - LONG INT - DOUBLE
d) CHAR - INT - LONG INT - FLOAT - DOUBLE
e) None of the above

7. What is the data type of the following expression:

22/7. + 3.14

a) Int
b) Float
c) Char
d) None of the above

8. The instructions typed by a programmer that will be compiled and executed by the computer are called:

a) Source code
b) Machine code
c) Object code
d) None of the above

9. What is wrong with the following code?

char szPassword[24];
gets(szPassword); // Get user password

if ( szPassword == "Joshua" ) printf("Welcome!");

a) The comparison method (==) will not work with strings.
b) GETS() does not input character strings.
c) The array declaration is invalid.
d) None of these

10. What output will be produced by the DO loop below?

int i=0;

do  {
     i++;
     printf("%d", i);
     }
     while(i<5);

a) 1 2 3 4 5
b) 0 1 2 3 4
c) 0 1 2 3
d) None of the above

11. Which statement below would correctly allocate an array of 500 integers by using the 'NEW' operator?

a) int* Array = new int[500];
b) new int Array[500];
c) Array[500] = new int;
d) None of the above

12. What is a structure?

a) A user-defined data type that can contains aggregate data
b) A special type of C pointer that can not be dereferenced directly
c) Another name for a C program
d) None of these

13. If the character sequence CR-LF ('\r' '\n') is encountered while reading a text file, what character sequence will result on the C side of the interface?

a) '\r'
b) '\r' '\n'
c) '\0' (NUL)
d) None of the above

14. Which stream below is normally associated with the keyboard?

a) stdout
b) stderr
c) stdprn
d) stdaux
e) None of the above

15. Why is it important to open a file in the binary mode when reading and writing in-memory contents such as structures?

a) To avoid undesired translation of certain memory content values
b) To allow automatic error checking of the file contents by the operating system
c) To minimize disk space requirements
d) None of the above

16. Which of these is a disadvantage of passing structures to functions by value?

a) Two copies of the structure occupy memory during the function's execution
b) Copying the structure is a relatively slow process
c) The function can not modify the original values in the structure
d) All of the above

17. The pointer value obtained from the 'FOPEN()' function (when used to open a disk file) is often referred to by programmers as a/an:

a) Array
b) Structure
c) Handle
d) None of the above

18. Which standard stream below could be used to talk to a printer?

a) stdout
b) stdprn
c) stderr
d) stdaux
e) None of the above

19. What happens when an object is instantiated?

a) The object is deleted or removed from memory
b) A pointer to the object is created
c) The object is dereferenced
d) None of these

20. Which operator is used to access the member elements of a structure?

a) "*"
b) "."
c) "&"
d) None of these

21. Suppose that the following memory allocation is performed:

Class CDonuts MyDonuts[100];

Which statement will execute the method TasteTest() in the sixth element of the array of objects?

a) TasteTest.MyDonuts[5];
b) MyDonuts[5].TasteTest();
c) CDonuts.TasteTest.MyDonuts(5);
d) None of the above

22. Which statement will correctly and dynamically allocate room for 13 (baker's dozen) CDonut objects?

a) CDonuts* NoSprinkles = new CDonuts[13];
b) CDonuts NoSprinkles[13];
c) NoSprinkles[13]->CDonuts[13];
d) None of the above

23. How does C++ discriminate between overloaded functions -- in other words, how does C++ know which version of an overloaded function to call?

a) By looking at the returned data type and comparing it with how the caller is using the function
b) By examining the parameter list and comparing it with the caller's parameters
c) By counting the number of times the function has been called
d) None of the above

24. The functions that are part of Class objects are called the:

a) Data members
b) Elements
c) Methods
d) None of the above

25. The method of a class that is called automatically when objects of that class are instantiated is called the:

a) Constructor
b) Initializer
c) Destructor
d) None of the above

26. In what file would you find the definition (prototypes) for a class called CGhostBuster?

a) GhostBuster.h
b) GhostBuster.cpp
c) CGhostBuster.c
d) None of the above

27. What parameter passing method of C++ gives the advantage of passing values by pointer, yet avoids the use of pointer notation in both the calling and called functions?

a) Passing by value
b) Passing by reference
c) Passing by array
d) None of these

28. What is the primary difference between objects defined with Class versus those defined with Struct?

a) The Class objects have active behaviors
b) The Struct objects have built-in data protection
c) There's no functional difference between them
d) None of the above

29. Suppose that the following overloaded function prototypes are given:

A) void Homer(int, char, float);
B) int Homer(double);
C) float Homer(double, int, int, double);

Which version will be called by the program statement:

Homer(35,'A', 3.14159);

a) Version "A"
b) Version "B"
c) Version "C"
d) Insufficient information

30. If a class member is defined as "private," who can access it?

a) Only functions within the same program
b) Any function within any process running on the computer
c) Only methods within the class itself
d) None of the above

Extra information for Exam 1:


You will be asked to write two short programs. In one program, you will instantiate an array of objects of a predefined type, and call one or more methods of each object. In the second program, you will write the code to overload two of the built-in operators for objects of a class. Make sure you know and understand the "formulas" for overloading operators!


Grade Exam!