COMP215 Practice Test II

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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. What is meant by the term "dereferencing?"

a) Finding the master inertial frame of reference
b) Accessing the memory contents addressed by a pointer
c) Finding the memory address of a value
d) None of the above

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

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

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

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

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

NOTE

When you take exam #2, you will also have to write some code. Make sure you know how to properly use pointers, character string handling functions, and arrays. You should also review the fundamentals from exam #1.


Press GRADE EXAM button to see how you did!

Grade Exam!