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: @ 18.97.14.86

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

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

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

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

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

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

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. Every C statement ends with what character?

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

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

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

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

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

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

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

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

16. What information must be passed to the STRCPY() library routine?

a) The length of each string, and the address of each string.
b) The address of each string.
c) The length of one of the strings.
d) None of these

17. The data being manipulated by a program is also known as:

a) The objects
b) The algorithm
c) The flow
d) None of the above

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

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

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

22/7. + 3.14

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

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

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

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

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

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

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

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

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

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

30. What are the objects in programming?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

I hope you have enjoyed this course!


Press GRADE EXAM button to see how you did!

Grade Exam!