Help on Practice Questions !!

closed account (LEwpfSEw)
I posted my own answers next to the question in Bold. Can someone please verify the answers for me.


If a statement doesn't have a,b,c,d answer options, treat
it as a True/False or an Either/Or assertion.


1 C was developed from the BASIC language in 1970. (T/F). F

2 Static functions may only be called by functions which are defined in the same source file. (T/F) T

3 Variables of type "double" are used instead of integers to
a. avoid being too specific about what value a number has
b. make possible the use of large numbers
c. permit the use of decimal points in numbers
d. conceal the true value of the numbers C

4 (T/F) Data inside a class may be hidden from access by functions outside the class body. private: protected: etc. T

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

6 The preprocessor mainly saves us a lot of typing by including other source files into our program source. T

7 Given: int a[10][5] ; to access 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 D

8 (T/F) For true randomness in a program, you must use the rand() function.
F

9 We use classes so that we can write some code one time and keep on re-using it later. T

10 (T/F) C++ string objects can grow larger or smaller as they are used.
T
11 When dealing with arrays, you will most often use:
a. while loops
b. for loops
c. do while loops
d. typecasts
e. none of these are related to arrays B

12 (T/F) Code for member functions in a class can be written outside the class' braces with only their prototypes inside the class declaration.
T
13 (T/F) Both malloc() and new[] return addresses.
T

14 In C++ fstream I/O, the function used to close a stream after writing to it is:
a. stream.exit()
b. stream.rewind()
c. stream.octet()
d. stream.close()
e. stream.release() D

15 Because of the execution of the statements: char ar[500]; char a, b, c ; the Visual C++ Express 2010 compiler will set aside
a. 500 bytes
b. 501 bytes
c. 502 bytes
d. 503 bytes
e. 504 bytes. D

16 (T/F) The main reason to prefer open() / read() / write() over fopen() fread() / fwrite() is their use of large buffers. T

17 Variables come in different types because:
a. Some variables are for counting and some for measuring.
b. Some variables cannot hold negative values.
c. Some variables are non-numeric.
d. Some variables come in larger and smaller sizes.
e. All of the above are true. E

18 When you compile a program you perform an act of translation.
T

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

20 Programs can choose between various actions to take by means of:
a. conditional operators
b. flow control
c. I/O
d. iterators
e. none of these A

21 All braces that surround code in a C program
a. delimit a section of code
b. hide code from the compiler
c. separate the code from the constants
d. separate the source file from the object file A

22 In C standard library I/O, the function used to disconnect a FILE * pointer from the disk hardware after writing is:
a. fclose()
b. close()
c. unlink()
d. chmod()
e. none above A

23 pointer is a variable which contains
a. signed float data
b. signed integer data
c. unsigned float data
d. unsigned integer data
e. signed character data D

24 In C standard library I/O, the function used to close a file after writing it is:
a. fclose()
b. close()
c. unlink()
d. chmod()
e. none above A

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

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

27 The wchar_t data type is for storing:
a. graphics
b. ASCII
c. Unicode
d. large objects
e. none of these C

29 Once you've fixed the compiler errors, the program is guaranteed to perform properly. (T/F). F

30 The C language is contained in C++. (T/F). T

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

32 (T/F) The switch() produces faster-executing code than several if()'s.
T
33 The code: int x = 9 ; cout << ++x ; will print:
a. 10
b. 9
c. 8
d. 1
e. error A

34 When your program ends, all of its variables go away, nothing is saved in the computer's memory for use the next time you run the program.
F

35 (T/F) The reference variable int &a may be made to point to several different objects during the run of the program. T

37 (T/F) A union allows several different types of variable to share the same memory. T

38 One of the methods NOT normally used to send data from the CALLED function to the CALLING function 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 C

39 C and C++ are languages in which the programmer writes readable source code which is then compiled into an executable binary. (T/F) T

40 (T/F) Given an array int arr[3]; , you can use the expression arr++.
T

41 The "char" type is really just a very small float. (T/F). F

42 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)
F

43 The Internet spread as fast as it did because Unix was written in C instead of Assembler. (T/F). T

44 Each C/C++ statement must end in a ; (semicolon). F

45 C is an Object Oriented Programming (OOP) language. (T/F). T

46 When you pass an array as an argument to a 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 A

47 Every C program must have one and only one function named MAIN() (T/F)
T
48 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 D

49 The files which #include <> fetches are human-readable text. (T/F).
T

50 (T/F) It is possible to successfully write a function yet not know how many parameters will be passed to it by the calling routine. F

closed account (LEwpfSEw)
51 (T/F) Computer programs can be written to write computer programs.
T

52 Many variables of the same Type, having the same Name, grouped together and referenced via an integer value constitute:
a. a class.
b. an array.
c. a struct.
d. a pointer.
e. none of these. B

53 To print the address 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 D

54 When a variable is defined inside of a { } block, it cannot be seen or changed from outside that block. (T/F). T

55 It is permissible to use reserved identifiers like "cout" and "printf" variable names in C++. T

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

57 When searching a sorted 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 B

58 How many bytes are taken up by 'C' and "C" respectively?
a. 1, 1
b. 2, 2
c. 1, 2 d, 2, 1
e. none of these C

59 Preprocessor directives take effect at
a. pre-compile time
b. run time
c. lunch time
d. edit time
e. no answer can be certain A

60 When class properties (data) are declared private:, they can be altered or accessed via:
a. static global functions
b. public methods of the class
c. inline functions
d. any of the above, equally
e. none of these B

61 Static int variables are 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)
T

63 If we call a function with the statement blotch(blue, green) what purpose do blue and green serve?
a. they are "arguments" we're passing to the function blotch()
b. they are the addresses of the function and the calling program
c. they are the addresses of the variables which we want blotch() to be able to access and/or modify.
d. they are the addresses of library routines needed by the function.
A

64 In a simple if() statement with no else, what happens 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 C

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

66 The expression static_cast<double>() is most similar to:
a. (double *)
b. (char *)
c. (int)
d. (double)
e. none of these D

67 Classes may contain both variables and functions. T

68 A variable:
a. always occupies 4 bytes no, char is always 1 byte, for instance
b. can contain values of any type a very general statement, probably safest
c. cannot have its contents changed once a value is assigned no, that's a constant
d. must be > 0 not if it's "signed"
e. none of these B

69 (T/F) "myclass::resize() {" starts the function definition (source code) for a method whose prototype appears in a class declaration. T

70 (T/F) Polymorphism consists of having several methods or functions with the same name and different argument lists. T

71 The #ifdef, #elif, #else, and #endif constructs 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 A

72 Assuming that range[] is a one-dimensional array of type int, which of the following refers to the address of the third element in the array?
a. *(range+2)
b. range[2]
c. range+4
d. range+2 A

73 (T/F) One of the reasons for using classes is that code may be more easily re-used instead of re-written. T

74 To allocate a two-dimensional array, a definition like: int arf[50,50] is used.
a. true
b. false F

75 In an expression containing relational, assignment, and arithmetic operators, they will be executed in the order:
a. assignment, relational, arithmetic
b. relational, arithmetic, assignment
c. assignment, arithmetic, relational
d. arithmetic, relational, assignment
e. none of the above. D

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

77 Given: float f , g ; . . . the better choice of the two comparisons below would be:
a. if (f >= g)
b. if (f == g) A

78 A C/C++ function can only return one value (unless it returns a pointer to an array). (T/F). T

79 To get a problem solved via computer we must:
a. run, compile, and edit our program
b. compile, run, and edit our program
c. edit, compile, and run our program
d. compile and run our program
e. compile, edit, and run our program C

closed account (LEwpfSEw)
80 (T/F) int y, x = 8 ; y = x++ ; will store a 9 in y. T

81 A class is a way of bundling (encapsulating) both data and functions (methods) into one "object". T

82 sprintf() can translate between decimal, Hexadecimal, and Octal. (T/F).
T
83
a. One C++ function can call another C++ function.
b. Only main() can call other functions(). A

84 (T/F) The identifying characteristic of the start of a word is:
a. a space character
b. isalpha()
c. isspace()
d. A printible character following whitespace B

85 Each class object has at least one "constructor" method associated with it, which runs when the object is created, but if you don't write one, a dummy constructor is provided. T

86 (T/F) A function with no parameters can only return a value with the "return" statement. T

87 Programs in the C++ language should be files which end in ".c".
F

88 In C++, we don't have to declare or define our variables before use, but it makes the program more understandable if we do. F

89 The file <cstdio> is:
a. a binary library
b. a shell script
c. a header file
d. a and c above
e. all above C

90 In ISO C++, if there is a global variable int x ; and within function fi() we find the definition float x = 0.1 ; we know that this:
a. makes the global variable "invisible" to the function fi()
b. still means the local variable is an int
c. forces the global to be a float
d. sets the global variable to 0
e. none of the above A

91 Which option stores a 0 in int variable ch, assuming the address of ch has been assigned to the pointer intprefv?
a. intprefv = 0 ;
b. *intprefv = 0 ;
c. *prevf = 0 ;
d. &prefv = 0 ;
e. *prefv = 0 ; B

92 Assuming 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 B


93 Define: Pass by Reference:
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 B

94 In building Unix, C was used for the kind of work that had previously only been done with Assembly Language.(T/F). T

95 TB What will happen if you assign a value to an element of a vector whose subscript exceeds the size of the vector?
a. the element will be set to zero
b. the vector will grow to the needed capacity
c. other data may be overwritten without warning
d. the system will flag an error and abort the run
e. either c or d may occur. E

96 If the program compiles without errors, it is sure to run correctly and give the right answers. F

97 If you want to read in the users name (first, (maybe a middle) , last) in a compleat, 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 C

98 (T/F) It is possible to print decimal-point-aligned financial data using std::cout without iomanip if you understand the sprintf() function.
T

99 The character '\n' causes the display of text to skip to the next line. (T/F). T

100 Preprocessor directives take effect at
a. run time
b. pre-compile time
c. link time
d. installation time
e. none above B



25. No. Check for yourself
27. Technically wchar_t is not required to be able to hold Unicode symbols and even to be larger that 8 bits.
30. Not every C program can be compiled by C++ compiler
31. fstream derived from both ifstream and ofstream. ifstream derived from istream etc. So no.
32 Not always. Depends on compiler ans switch/ ifs in question
34. All memory are cleaned by OS. Nothing remains after program finishes
35. No. Referenced object are defined in the moment reference is created.
39. /sarcasm on
readable source code
Depends on programmer
/sarcasm off
40 == 25
42. True, Like with normal function.
43. False. Internet and Unix have little direct relation.
45. C is not an OO language. C++ is.
47. It is main() not MAIN()
50. Yes. there is ellipses (...)

I am too lazy to read more.
Some of the questions require quite in-depth knowledge of language to answer absolutely correct.

Also this is not the place to check your homework. Nobody wants to read and check walls of text
Last edited on
I did not look through all your questions but I would like to note that for example question #46 has no a valid answer. It is the address of the first element of the array that is passed to function. The address of the array is something different.

46 When you pass an array as an argument to a 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 A

As for question # 47

47 Every C program must have one and only one function named MAIN() (T/F)
T

then neither C++ nor C must have function named MAIN though any program in C/C++ can have such a function. I think that the author of the question meant function main, not MAIN.:)
Last edited on
The following answer for the question is wrong.

80 (T/F) int y, x = 8 ; y = x++ ; will store a 9 in y. T

y will be equal to 8.:)
90. You still able to access global variable using global scope resolution operator (::x).
86. Relating to 38: you still can return through global variable :).
84. Depends of definition of "word"
77. It is two different comparsion for two different needs and one cannot be substitute for other. Both are not reccomended to use directly.

Many questions repeat itself, many are obscure and ambiguous.
Last edited on
9. This sounds like the reason why we use functions. Classes is more about grouping data and functions together, and all that OOP stuff.

31. Not sure why they call them objects. ifstream, ofstream and fstream are classes.

34. I think you are correct because hard drives is a kind of memory.

56. I don't think so. C++ has a stricter type system so it can make assumptions that a C compiler can't.

69. Don't forget the return type of the function.

72. range+2 will give you a pointer to third element of range.
Last edited on
vlad from moscow wrote:
I did not look through all your questions but I would like to note that for example question #46 has no a valid answer. It is the address of the first element of the array that is passed to function. The address of the array is something different.

46 When you pass an array as an argument to a 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 A


The array and the first element in the array will be stored at the same address so A is correct.
closed account (LEwpfSEw)
Thank you for your guys' help! Greatly appreciated. Gonna Ace the test now.
Peter87 (4393)
The array and the first element in the array will be stored at the same address so A is correct


If you have an array for example int a[10] then the address of the array is the expression &a. It is not the same as the address of the first element of the array.
1
2
3
4
5
6
7
8
#include <iostream>

int main()
{
	int a[10];
	std::cout << &a << std::endl;
	std::cout << a << std::endl;
}
0x7fff1032c4a0
0x7fff1032c4a0

I know the pointer types is not the same if that's what you mean.
@Peter87

I know the pointer types is not the same if that's what you mean.


So the pointer to the first element of an array is not the same as a pointer to the array.
OnceKnown:

"...Thank you for your guys' help! Greatly appreciated. Gonna Ace the test now..."

Oh really? We'll see about that. Come see me in Office Hours this Monday if you want to minimize damage.

TH
3) B and C are both technically correct. I would go with B though since a simple float could be used for a decimal number.
Last edited on
Oh really?

0_o
KRAkatau wrote:
I would also disagree on q. 70
http://www.cplusplus.com/doc/tutorial/polymorphism/

Function overloading is a form of polymorphism.
http://en.wikipedia.org/wiki/Ad-hoc_polymorphism
Certainly. But the question is stated like "polymorphism consists of ...". I'd interpret it as "polymorphism is only...". Well, I guess it's rather ill-posed question :)
Write in the margin "if you mean..."
Topic archived. No new replies allowed.