Multiple Choice Question Bank

(Last Mod: 27 November 2010 21:38:38 )

ECE-1021 Home



Exam #1 Question Bank

1)       Which of the following statements does not have the same effect as all the others?

  1. k = k+1;

  2. k =+ 1;

  3. ++k;

  4. k += 1;

2)       What are the values of the variables after the following statements are executed?

j = 1;

k = j++;

m = (++k  = = j++);

  1. j = 2   k = 2  m = 0

  2. j = 3   k = 3  m = 1

  3. j = 3   k = 2  m = 1

  4. j = 3   k = 2  m = 0

3)       Which of the following are complementary pairs of operators?

  1. (= = , !=), (>,<), (>=, <=)

  2. (= = , !=), (>=,<), (>, <=)

  3. (= = , !=), (>,>=), (<=, <=)

  4. (= = , !=), (>,<), (>=, =<)

4)       If j = 0, k = 2 and m = 14, what value is stored in n?  

n = (k && m) + (j < (k/m)) + (j || (!m)) +(m/k);

  1. 0

  2. 1

  3. 7

  4. 8

5)       Which operator is not defined for floating point data types?

  1. %=

  2. &&

  3. <=

  4. +=

6)       Which of the following statements is false?

  1. A logical operator will always return a value of 0 or 1.

  2. A value is a logical FALSE if it is equal to 0.

  3. A value is a logical TRUE if it is equal to ?1.

  4. Negative values cannot be interpreted as logical values.

7)       Modulo division of m by n (m%n) is used to return

  1. The result of an integer division.

  2. A value of 1 if m can be evenly divided by n.

  3. The same value that would be returned by m ? n*(m/n).

  4. The result of a floating point division even if the operands are integers.

8)     Which of the following assignments produces a value of zero?

  1. result = 9%3 ? 1;

  2. result = 8%3 ? 1;

  3. result = 2 ? 6%3;

  4. result = 2 ? 8%3;

9)    Consider the following statement:  int i = 100, j = 0; Which of the following statements is true?

  1. i < 3

  2. !(j<1)

  3. (i>0) || (j>50)

  4. (j<1) && (i<=10)

10)    What is the value of the following expression?

 (!((4-4%3) < 5 && (6/4 >3)))

  1. true.

  2. false.

  3. invalid.

  4. none of the above.

11)    What must be true of an else statement?

  1. It must contain a logical test.

  2. It must appear immediately after an if() statement in the program structure.

  3. It is associated with the closest if() statement above it.

  4. It must be properly indented for the compiler to determine which if() statement is controlling it.

12)    What must be true of a switch() statement.

  1. The controlling expression must return an integer result (which includes chars).

  2. A default case is required and must appear last in the case list.

  3. The only way to exit a switch() structure is through the use of the break statement.

  4. Multiple values can be listed on the case line ? such as case 1,2,3 :

13)    Why does C offer three different looping structures?

  1. Because no one looping structure can implement all of the different types of loop logic that might be needed by a program.

  2. Because the for() loop is only capable of executing a finite and predetermined number of times and the while() loop is not guaranteed to execute the loop code at least once.

  3. Because each structure lends itself to a certain type of looping logic and program readability and maintainability are enhanced if the structure used matches the logic implemented.

  4. For compatibility with other languages.

14)    What is the purpose of indenting various lines of code different amounts?

  1. It is a requirement of the language ? the amount of indenting is used by the compiler to determine code structure.

  2. It is purely to aid the programmer in determining code structure quickly and accurately ? the compiler ignores all indenting.

  3. The indenting of certain functions, such as loops and if()...else structures, are mandatory and the rest is just to make the appearance of the code more consistent.

  4. It is purely for aesthetic value and is completely arbitrary. There is no significant advantage to indented code versus non-indented code.

15)    What are the three basic building-block structures of a structured program?

  1. Input statements, output statements, computation statements.

  2. Goto?s, loops, I/O.

  3. Sequences, selections and repetitions.

  4. Looping structures, switching statements, computed goto statements.

Exam #2 Question Bank

All questions from the Exam #1 Question Bank are fair game for Exam #2

16)       What is the purpose of type casting?

  1. To create new data types.

  2. To change the data type of a variable.

  3. To convert the data stored in a variable to a different type before using it in an expression.

  4. To prevent the loss of data when passing values to functions.

17)       What is the proper format specifier for an argument of type double?

  1. %d in both scanf() and printf().

  2. %f in printf() and %lf in scanf().

  3. %lf in both printf() and scanf().

  4. %f in printf() and %d in scanf().

18)    Which of the following is a valid function definition statement?

  1. function cube (double x)

  2. double cube (double x)

  3. double cube (x)

  4. cube (double x)

19)    In a function call, the actual parameters are separated by

  1. commas.

  2. semicolons.

  3. colons.

  4. spaces.

20)    Which of the following is not a purpose of a function prototype?

  1. To force the compiler to use the return type specified by the prototype.

  2. To permit the compiler to compile code where it encounters a call to the function prior to encountering the function definition itself.

  3. To permit the function definition to be kept in a completely different .c file.

  4. To allow the compiler to do type checking on function calls.

21)    What is the difference between the following two statements?

#include <filename.h>

#include ?filename.h?

  1. The <> version can only be used for standard library files.

  2. The ?? version looks for the file in the specified path or current directory first.

  3. The ?? version is for C++ header files and the <> version is for C header files.

  4. There is no difference, both are allowed and are equivalent.

22)    What is the value of 

fives(ceil(sqrt(62.5)))?

where:

int fives(int n) {return( ((n%5) != 0) );}  

  1.   0

  2. 1

  3. 7

  4.  8

23)    Which of the following is not an advantage of modularizing a program?

  1. The problem can be broken down into self-contained sub-problems.

  2. The code can be designed, implemented and tested in manageable pieces.

  3. The code can be reused both in the same project and in future projects.

  4. The details of how individual tasks are performed is readily apparent to all users.

24)    What is a sentinel signal?

  1. A special data record used to indicate the last record in a data file.

  2. An special variable whose value is set by fopen() and that can be queried to determine the reason that a file open operation failed.

  3. Any out-of-bounds condition such as division-by-zero that would indicate a problem with the code logic.

  4. A value stored at the beginning of a data file telling how many valid records are in the file ? also known as a header record.

25)    If you desire to print certain characters using printf(), such as ? and ?, you must precede them with a special character. What is that character:

  1. %

  2. \

  3. /

  4. &

Exam #3 Question Bank

All questions from the Exam #1 and Exam #2 Question Banks are fair game for Exam #3

26)    The value stored in a pointer variable represents

  1. The initial memory location of the program's data segment.

  2. The address at which some piece of information is stored.

  3. The address of the beginning of a text string.

  4. The address of the beginning of an array.

27)    The functions fset(), fread(), and fwrite() are typically used with files opened for

  1. text operations.

  2. binary operations.

  3. append operations.

  4. random access operations.

28)   Which of the following types of I/O operations are normally carried out on text files?

  1. character, formatted, and unformatted.

  2. string, formatted, and unformatted.

  3. character, string, and unformatted.

  4. character, string, and formatted.

29)   Which of the following are differences between structures and arrays?

  1. Structures are passed by value while arrays are passed by reference.

  2. Structures are not limited to containing variables of a single data type..

  3. Structures can contain elements that are pointers.

  4. Structures and arrays use different operators to access their elements.

30)  What is the practice of freeing dynamically allocated memory that is no longer needed referred to as?

  1. Memory block management.

  2. Heap maintenance.

  3. Preemptive deallocation.

  4. Garbage collection.

31)  Which of the following pairs of statements are identical?

  1. (*ptr).element  AND  ptr>element

  2. (*ptr)>element  AND ptr.element

  3. *ptr.element  AND ptr>element

  4. *ptr>element  AND  ptr.element

32)   A "stack" is also known as what?

  1. a FIFO (First In, First Out).

  2. a Queue.

  3. a LIFO (Last In, First Out).

  4. a Linked List.

33)   A "queue" is also known as what?

  1. a FIFO (First In, First Out).

  2. a stack.

  3. a LIFO (Last In, First Out).

  4. a Linked List.

34)  What is meant by an "automatic" storage class ?

  1. A variable that is automatically initialized by the system before its first use.

  2. A variable whose storage is automatically allocated and deallocated as needed at run time.

  3. A variable that can automatically adjust to data of different types.

  4. A pointer, since a pointer can point to any type of data.

35)   When is a "static" variable initialized?

  1. Every time the function containing it is called.

  2. When it is globally declared.

  3. Only when declared within a function other than main().

  4. Only the first time the function containing it is called.

36)   A "linked list" always contains elements that can be described as?

  1. Redundant.

  2. Recursive.

  3. Self-referential.

  4. Bidirectional.

37)   The combination of a structure and a set of functions that act on it are a precursor to what?

  1. A module.

  2. The concept of an "object" in C++.

  3. A function structure.

  4. A compound structure.

38)   What is not an advantage of defining a small set of "primitive" functions that are on the functions allowed to directly operate on a structure's elements and then requiring that all other functions that need access do it only via these primitives?

  1. The details of how data is organized within the structure can be abstracted (a.k.a., hidden) from the user..

  2. Changes to how the data is organized within the structure will only require modifications to the primitive functions.

  3. A small set of primitives results in more efficient code in terms of execution speed.

  4. The frequently confusing task of structure dereferencing is limited to a small number of functions, namely the primitive functions. 

39)   What is the practical difference between a typedef statement and a similar #define statement?

  1. A #define statement cannot be expanded on a variable declaration line .

  2. A #define may not behave as expected if a pointer is part of the definition.

  3. There is no comparison - they are completely different things.

  4. There is no difference..

40)   In a function prototype or definition header, which of the following pairs are equivalent data types?

  1. int *a[]  AND  int **a

  2. double ***a AND double *a[*]

  3. void *a AND void **a[]

  4. char *s  AND string s