COMP215 Practice Final Exam

Instructions: There are 50 questions on this test. It is written in a style very similar to the REAL final exam. 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.12.120.25

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

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

3. Given the following declaration:

int Values[4]={1,2,3,4};

What value will be returned if the expression "*Values" is evaluated?

a) 2
b) 1
c) &Values[0]
d) 4
e) None of these

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

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

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

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

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

7. What are the objects in programming?

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

8. What is the default data type returned by C functions?

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

9. What will the output of the following code be?

double Zeta; // Holds ratio of alpha/w(nat)

Zeta = 0.707107; // Less than critically damped system
printf("Damping ratio = %10.1lf\n", Zeta );

a) Damping ratio = 0.707107
b) Damping ratio = 0.707
c) Damping ratio = 0.7
d) None of these

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

11. Which of these lists the products of a C compilation session in correct order?

a) Assembly code - Source code - Object code - Machine code
b) Machine code - Object code - Source code - Assembly code
c) Source code - Assembly code - Object code - Machine code
d) None of these

12. What is the meaning of the following declaration?

float* pVar;

a) pVar is a pointer to data of type FLOAT
b) pVar is a floating point variable
c) pVar is meant to have an initial value of zero
d) None of these

13. Which of these would be BEST to do before using a pointer to access memory?

a) Make sure sufficient memory exists to use the pointer.
b) Check to see if your C compiler supports pointers.
c) Make sure the pointer address is valid
d) None of these

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

15. In C, how is a logical OR indicated?

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

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

17. What is the effect of a return statement within MAIN()?

a) The program starts over at the first statement in MAIN()
b) The program ends and control goes back to the operating system
c) The last executed instruction repeats
d) None of the above

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

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

19. What is special about the NULL pointer value?

a) The NULL pointer automatically dereferences the target object.
b) Arrays can only be accessed if a NULL pointer is used.
c) The NULL pointer is obtained when a disk I/O error occurs.
d) None of these

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

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

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

22. What is something that can not be done with a VOID pointer?

a) Dereferencing
b) Assignment of pointer value
c) Type-casting pointer contents to another type
d) None of these

23. What character code is used to end all strings in C?

a) '\n'
b) '\0'
c) '\7'
d) None of these

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

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

26. Given the following declaration:

int Values[4]={1,2,3,4};

What value will be returned if the expression "*(Values+2)" is evaluated?

a) 2
b) 1
c) 3
d) Insufficient information given to solve problem.

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

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

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

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

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

32. Which standard stream below could be used to talk to the video display?

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

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

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

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

35. Given the following declaration:

struct Complex
    {
    double re;
    double im;
    };

If a DOUBLE uses 8 memory locations, how much memory is used up?

a) 8 locations
b) 16 locations
c) 0 locations
d) None of these

36. What must be done with any objects created through the 'NEW' operator prior to termination of a program?

a) The objects must be tested to see if they hold proper values
b) The objects must be tested with the 'OLD' operator
c) The objects must be deleted from memory
d) None of the above

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

38. Given the following declaration:

struct Complex
    {
    double re;
    double im;
    };

Complex Values[ xx ];

If there are 1732 memory locations free, what is the maximum value that "xx" can have, assuming that a DOUBLE uses 8 memory locations?

a) 216
b) 108
c) 132
d) None of these

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

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

40. What value is returned by the NEW operator when a memory allocation request fails?

a) -1
b) NULL pointer
c) 0xffff
d) None of the above

41. Which of these is a disadvantage of Stroked (Vector) fonts?

a) A large amount of memory is required
b) Only one color of text can be displayed
c) Rendering is a complex and slow process
d) None of the above

42. When a text file has been opened and a newline '\n' character is written into it by a C program, what character sequence is actually created in the file?

a) '\n' (LF)
b) '\r' (CR)
c) '\r' '\n' (CR - LF)
d) None of the above

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

44. Given the following declaration:

struct Complex
    {
    double re;
    double im;
    };


double GetMagnitude(Complex* lpStr)
{
//...
}

To access the member 're' within the function, what notation would be used?

a) lpStr->re
b) lpStr.re
c) re
d) None of the above

45. In the Borland Graphic Interface, the coordinates (0,0) represent what?

a) The ULH corner of the video display
b) The URH corner of the video display
c) The center of the video display
d) None of the above

46. What must be done with open files prior to ending a program?

a) Close them
b) Write the final information into them
c) Check their contents
d) None of the above

47. What two pieces of information are needed by 'FOPEN()' ?

a) A drive letter and file mode specifier
b) A filename and file mode specifier
c) A file mode specifier and system password
d) None of the above

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

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

50. Which type of font below looks best when shown at different magnification levels on a video screen?

a) Bit-mapped
b) Imaginary
c) Stroked (Vector)
d) None of the above

I hope you have enjoyed this course!


Press GRADE EXAM button to see how you did!

Grade Exam!