COMP122 Practice Test I

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

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

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

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

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

3. Every C statement ends with what character?

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

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

7/3

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

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

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

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

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

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 is the data type of the following expression:

22/7. + 3.14

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

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

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

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

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

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

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

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

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

17. If A=1 upon entry into the code below, what will be output?

switch (a)
     {
     case 1: printf("TV is on.");

     case 2: printf("Stereo is on.");
         break;

     case 3: printf("Room lights dimmed.");
         break;

     default: printf("Say what?");
         break;
     }

a) TV is on.
b) TV is on. Stereo is on.
c) Room lights dimmed.
d) Say what?

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

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

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

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

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

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

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

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

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

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

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

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

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

NOTE

When you take exam #1, you will also have to write some code. Make sure you know how to punctuate PRINTF statements, write IF-ELSE statements, and write FOR/DO/WHILE loops.


Press GRADE EXAM button to see how you did!

Grade Exam!