COMP122 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.14.141.177

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

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

3. Given the declarations:

char szData[64];
int i;

i=314;

Supposed that we wish to place a text message into szData that shows the value in variable i. Which of the statements below would accomplish this?

a) strcpy( szData , "i = %d", i);
b) sprintf( szData , "i = %d" , i );
c) strcat( szData , i , "i = %d" );
d) None of these

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

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

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

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

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

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

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

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

9. Given the following declaration:

char szName[24];

How many characters can be in the array (excluding the terminator)?

a) 24
b) 25
c) 23
d) None of these

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

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

11. What are the objects in programming?

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

12. What is wrong with the following code?

int nValue = 25;
float* fAddr;

fAddr = &nValue;
*fAddr = *fAddr + 1;

a) It is illegal to use the expression *fAddr on the left side of an equals sign.
b) The pointer "fAddr" has not been loaded with the address of an object.
c) The pointer "fAddr" is of the wrong type (float*).
d) None of these

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

14. What is one dangerous situation that can occur when programming character string input in C?

a) Using up excessive amounts of memory.
b) Taking up too much CPU time requirements, which can slow down the disk system.
c) Having insufficient space in an array to hold all the user's input.
d) None of these

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

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

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

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

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

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

20. Given the following declaration:

int Values[25];

Which expression below is equivalent to: &Values[0]?

a) Values[0]
b) Values[-1]
c) Values
d) None of these

21. Every C statement ends with what character?

a) ','
b) '*'
c) ';'
d) None of the above

22. Which declaration below would be correct to make "pVar" a pointer to int type?

a) int pVar;
b) int* pVar;
c) int &pVar;
d) None of these

23. Given the following declaration:

int Values[25];

Which expression below is equivalent to: Values?

a) &Values[0]
b) Values[0]
c) Values[-1]
d) None of these

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

int a,b;

b = 24;
a = ++b + 10;

a) 34
b) 35
c) 33
d) None of the above

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

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

22/7. + 3.14

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

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

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

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

29. What conditions must be present for the fragment below to print the message "B is too small?"

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

a) (a < 20)
b) (a > 20) and (b >= 10)
c) (a>=20) and (b < 10)
d) None of the above

30. What is the data type of the following expression?

"The quick brown fox jumped over the lazy dog."

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

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

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

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

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

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

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

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

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

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

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

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

40. What is a stream?

a) A path of communication between a program and the operating system
b) A method for writing to the video screen
c) A method for checking the contents of variables
d) None of the above

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

42. When programming graphics under the DOS environment, what is typically done first within a program?

a) Close all open files
b) Read and save the current video mode
c) Clear the video screen
d) None of the above

43. Given the following declaration:

struct Complex
    {
    double re;
    double im;
    };

Complex Values[10];

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

a) 160
b) 80
c) 40
d) None of these

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

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

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

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

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

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

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

I hope you have enjoyed this course!


Press GRADE EXAM button to see how you did!

Grade Exam!