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

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

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

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. What type of data must be in variable A below?

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

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

5. Every C statement ends with what character?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

7/3

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

48. Which standard library function below is used to move the file position indicator when implementing a random-access binary file system?

a) fopen()
b) fseek()
c) fputs()
d) None of the above

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

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

I hope you have enjoyed this course!


Press GRADE EXAM button to see how you did!

Grade Exam!