COMP215 Practice Test I

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.15.190.144

1. How does a programmer give a preprocessor directive?

a) By starting a line with the '//' sequence
b) By ending a line with the '*/' sequence
c) By starting the line with the '#' character
d) None of the above

2. 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

3. To print a FLOAT with a field width of 10 and 2 digits to the right of the decimal point, what PRINTF format specifier should be used?

a) "%8.2lf"
b) "%10.2f"
c) "%12.2d"
d) None of the above

4. In order to solve a problem using a programming language, what must be done first?

a) Determine an algorithm that solves the problem
b) Write computer source code instructions
c) Define the problem
d) None of the above

5. What will be in variable 'A' after executing the following code?

int a,b;

b = 24;
a = b++;

a) 24
b) 25
c) 23
d) None of the above

6. What is object code?

a) Incomplete machine code
b) Instructions typed in by the programmer
c) The result of the C preprocessor's operation
d) None of the above

7. What is the result of evaluating the following expression?

22/7. + 5/3

a) 4.142857...
b) 4.809523...
c) 5
d) None of the above

8. What are the objects in programming?

a) The computer's instructions
b) The data
c) The constants
d) None of the above

9. How are comments marked in C++?

a) With the ';' character
b) With either '//' (start of line) or '/* .. */'
c) With the '++' sequence
d) None of the above

10. What type of data must be in variable A below?

printf("A = %d now.\n", a );

a) int
b) char
c) float
d) double

11. For the code below to print the message "OK", what conditions are needed?

if (a<20) && (b == 25)
     printf("OK");

a) A must be more than 20, OR B must be equal to 25
b) Either A must be less than 20, OR B must be not equal to 25
c) A must be less than 20, AND B must be equal to 25
d) None of the above

12. If A=2 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

13. 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

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

switch (a)
     {
     case 1: printf("TV is on.");

     case 2: printf("Stereo is on.");
         break;

     case 3: printf("Room lights dimmed.");
         break;

     default: printf("Say what?");
         break;
     }

a) TV is on.
b) TV is on. Stereo is on.
c) Room lights dimmed.
d) Say what?

15. When is a C expression considered to be 'true?'

a) When it is non-zero
b) When it is zero
c) Whenever it is not false
d) None of the above

16. Given that A=25 and B=10, what will the output of the fragment below be?

if (a<20)
     printf("Too Small.");
     else
     if (b >= 10)
         printf("Everything is OK.");
         else
         printf("B is too small.");

a) Too Small.
b) B is too small.
c) Everything is OK.
d) None of the above

17. In C, a logical AND is indicated by what operator?

a) &&
b) ||
c) ++
d) None of the above

18. A 'for' loop is written as follows:

for(i=0 ; i<25 ; i++)
     printf("Testing %d\n", i);

What will the highest and lowest printed values of 'i' be?

a) 1 and 25
b) 0 and 26
c) 0 and 24
d) None of the above

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

int i=2;

do  {
     i++;
     if (i==7) continue;
     printf("%d", i);
     }
     while(i<10);

a) 3 4 5 6 7 8 9
b) 2 3 4 5 6 7 8
c) 3 4 5 6 8 9 10
d) None of the above

20. What will be the output of the following FOR loop?

for(i=0 ; i<5 ; i++)
     {
     if (i==2) continue;
     printf("%d", i);
     }

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

21. What will be the output of the following FOR loop?

for(i=0 ; i<5 ; i++)
     {
     if (i==2) break;
     printf("%d", i);
     }

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

22. A 'for' loop makes its test:

a) At the top of the loop
b) At the bottom of the loop
c) Either the top or the bottom of the loop, as the programmer desires
d) None of the above

23. 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

24. 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

25. A certain function has the following prototype:

float MyFunct(int x, float z);

Which statement below correctly calls this function? Assume that A and B are type INT, and C is type FLOAT.

a) MyFunct( a, b);
b) a = MyFunct( 0, a);
c) c = MyFunct( a, 1.41459 );
d) None of the above

26. A certain function is written as follows:

MyFunct(int x)
{
return(x * x);
}
What is the data type returned by this function?

a) char
b) int
c) float
d) None of the above

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

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

MyFunct(x, y);

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

28. What is wrong with the function below?

float MyFunct(int x, float z)
{
float x2;

x2 = z*z + x;
}

a) Function defined as type FLOAT but fails to return a value
b) A semicolon is required on the first line 'float MyFunct(int x, float z);'
c) The function is returning the wrong data type (INT)
d) None of the above

29. How many passes does the C compiler make through the source code?

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

30. When do C functions need to be prototyped in single-source-file projects?

a) Prototyping is always optional in C as long as a single file contains all the source code.
b) When functions are called before they are defined (i.e., function 'below' use in listing.)
c) Prototyping is always required, regardless of where the functions are used.
d) None of the above

NOTE

When you take exam #1, you will also have to write some code. Make sure you know how to punctuate PRINTF statements, write IF-ELSE statements, write FOR/DO/WHILE loops, and prototype/use FUNCTIONS.


Press GRADE EXAM button to see how you did!

Grade Exam!