A Few Questions

So I have a test coming up that I'm kind of worried about. This is the study guide of the material and I put my answers to the problems. I was hoping if anyone looks it over and sees problems that I did wrong they can correct me.

1. The o perators: & | ^ are:

a) AND OR NOT
b) AND OR XOR
c) AND NOT NAND
d) AND NOR XOR
e) none of these

2. Ident ical programs using only C syntax will tend to run slower when
compiled as C++ rather than C. (T/F).

3. Assu ming that spread[] is a one-dimensional
array of type int, which of the following
refers to the value of the third element in the array?

a. *(spread+4) b. spread[2]
c. spread[3] d. spread+2

4. TF Both malloc() and ne w[] return addresses.

5. C is an Ob ject Oriented Programming (OOP) language. (T/F).

6. The entire C programming language is contained within
the C++ programming language (T/F).

7. One of the methods NOT normally used to send data from the CALLED function to the CALLING fun ction in C is:
a. global variable
b. pointer to variable in calling function
c. instruction pointer register
d. return value of called function
e. none of the above

8. A be nefit of C++ is:
a. reusable code via Inheritance.
b. modularization via Encapsulation.
c. abstraction thru the use of Templates.
d. all of the above.
e. none of these.

9. The constant "C" occu pies how many bytes?
a. 4 b. 3 c. 2 d. 1 e. none of the above

10. Many variables of the same Type, having the same Name,
grouped toge ther and referenced via an integer value
constitute:

a. a class.
b. an array.
c. a struct.
d. a pointer.
e. none of these.

11. Define: Pass by Refere nce:

a. pass a copy of the variable's contents on the stack
b. pass the address of the variable on the stack
c. write a temp file to disk
d. write a temp buffer to working storage
e. none of the above

12. De fine: Pass by Value

a. pass a copy of the variable's contents on the stack
b. pass the address of the variable on the stack
c. write a temp file to disk
d. write a temp buffer to working storage
e. none of the above


13. Given:
float f , g ;
.
.
.
the better choice of the two comparisons below would be:

a. if (f >= g)
b. if (f == g)

14. To copy the cont ents of int b[200] to int a[200], you would:

a. a = b ;
b. memcpy(a, b, sizeof(a)) ;
c. use a correctly written for() loop
d. b or c above
e. a, b, or c above

15. If you want to read in the users name (first, (maybe a middle)
, last) in a complete, single line from the keyboard, then parse that
line later on, your usual method would be:

a. cin >>
b. cin.get()
c. cin.getline()
d. each is as good as the others
e. only a and b would work

16. Given:

int a[10][5] ;

to acces the second item in the
3rd row, we would use:

a. a[2][3] ;
b. a[3][2] ;
c. *(*(a+3)+2) ;
d. *(*(a+2)+1) ;
e. none above

17. The #ifdef, #elif, #else, and #endif
con structs are used to:

a. decide what code the compiler includes in the program
b. control program execution at run time
c. pass arguments back to dos during program execution
d. both a and b above
e. all of the above

18. In C standard library I/O, the function
used to disconnect a FILE * point er from the
disk hardware after writing is:

a. fclose()
b. close()
c. unlink()
d. chmod()
e. none above

19. The ifstream and ofstream objec ts are both examples of
object creation by inheriting from the fstream object. (T/F).

20. sprintf() can tran slate between decimal,
Hexadecimal, and Octal. (T/F).

21. Object Ori ented Programming uses "objects" which
may contain:

a. data
b. executable code
c. either data or executable code, not both
d. both a and b plus other class objects
e. none are true

22. When searching a sor ted array:

a. linear searching is more efficient
b. binary searching is more efficient
c. efficiency is a function of array type
d. binary is faster only if it is an array of floats
e. none of these are true

23. To do array processing, it is necessary to know
the size an array will be when you are writ ing the
program. (T/F).

24. To print the add ress of x given: int x, * pt; pt = &x ; you would
a. printf("%X\n", pt) ;
b. printf("%X\n", &x) ;
c. printf("%X\n", *pt) ;
d. a & b above
e. none of the above


25. An array may never be initi alized at compile time
a. true b. false

26. Suppose an array has been defined as int arr[3]; , can you use the expr ession arr++ ?
a. yes b. no

27. To allocate a two-dimensional array, a defini tion like: int arf[50,50] is used.
a. true b. false

28. When you pass an array as an argument toa function, what is actually passed?
a. the address of the array
b. the values of the elements in the array
c. a duplicate of the array
d. the number of elements in the array
e. none of the above

29. An assignment statement itself has a value, just like a variable. (T/F)

30. In a simple if statement with no else, what happ ens if the condition is false?

a. the program searches for the last else in the program
b. nothing
c. control "falls through" to the statement following the if construction
d. the body of the if statement is executed

31. The purpose of the " ? : " operator is to:

a. select the highest of the two values
b. select the more equal of two values
c. select one of two values alternately
d. select one of two values depending on a condition
e. none of the above

32. The statements following else in an if-else construction are executed when

a. the conditional expression following if is false
b. the conditional expression following if is true

33. It is possible to print decimal-point-aligned
financial data using cout using the sprintf() function. (T/F).

34. A non-static global variable may be altered
by functions which are declared in any source file
included in the project. (T/F)

35. A static function may only be called by
functions which are defined in the same
source file. (T/F)

36. A static int variable is allocated only
once in the run of the program, and keeps its
value between calls of the function in which
it is defined. (T/F)

37. C variables declared inside a function {}
are visible only to the calling routine. (T/F)

38. Given:
main(int argc, char *argv[], char ** env)

argv[0] is local only to main, and may not be directly
seen or used by any other function. (T/F)

39. static_cast<double>() is most similar to:

a. (double *)
b. (char *)
c. (int)
d. (double)
e. none of these

40. Given: int a = 8 , b = 9 ;
in order to get an accurate quotient, you must do:

a. cout << a / b ;
b. cout << (double) a / b ;
c. cout << (double) (a / b) ;
d. b or c above.
e. they all produce an accurate answer.


1. B
2. T
3. B
4. T
5. F
6. A
7. C
8. D
9. C
10. B
11. C
12. A
13. A
14. D
15. A
16. E
17. B
18. A
19. T
20. F
21. A
22. B
23. F
24. D
25. F
26. B
27. F
28. A
29. T
30. C
31. D
32. A
33. F
34. T
35. T
36. T
37. F
38. T
39. D
40. B
1) Correct
2) Incorrect, they will run the same speed if the libraries/headers are the same. FYI, some C++ compilers simply convert the C++ code to C then run a C compiler on it
3) Correct
4) Maybe incorrect, they return pointers (although though you could call them addresses I suppose, I've never seen anyone do that)
5) Correct, unless by "is an OOP language" they mean "supports OOP"
6) Is a true of false question, but you put A...>_>
7) Correct, although I would say A as well because it is bad practice and shouldn't be done anyway
8) Correct
9) Correct
10) Correct, although you could also use a pointer since arrays are basically pointers
11) Incorrect, I'd pick B here...C is completely unrelated. Go check the tutorial here on references and hopefully you'll figure it out
12) Correct
13) Correct...although they should have provided more context since >= isn't really the same as == ever
14) Correct
15) Incorrect, I think they want C here, key words being "all at a single time". A and B would be getting only part at a time. However, I would say none of the above, use std::getline() instead.
16) Incorrect...D I think. I think C arrays go array[column#][row#] Also, pointer arithmetic FTL.
17) Incorrect, go look up "Pre-processor statements" in the tutorial here
18) Correct
19) Incorrect, they inherit from istream and ostream respectively...although this is a really dumb question IMHO
20) Incorrect, you can use sprintf() to that by passing an octal/etc number and outputting it as a different base
21) Incorrect, should be D.
22) Correct
23) Correct
24) Correct
25) Correct, although you put F, not B
26) Correct, TBH, I tried this to see XD
27) Correct, you should probably use a wrapper class anyway...
28) Correct, address == pointer to it
29) Correct
30) Correct, if it means "skip the body of the if statement"
31) Correct
32) Correct
33) Incorrect...sort of. You can't pass cout directly but you could use a combination of format specifiers and/or string formatters to make it work
34) Correct
35) Correct, although you shouldn't do this, use an unnamed namespace instead, using static this way is depreciated
36) Correct
37) Incorrect, functions have a scope, just like if statements and for loops
38) Correct
39) Correct
40) Correct

Btw, would be nicer if you put the answers right next to the questions, heh.
Topic archived. No new replies allowed.