Ayush
Ayush

Reputation: 42450

Some exam questions about C++ vectors and arrays

Hey guys, I have a CS exam tomorrow. Just want to get a few questions cleared up. Thanks a lot, and I really appreciate the help.

Que 1. What are parallel vectors?

  1. Vectors of the same length that contain data that is meant to be processed together
  2. Vectors that are all of the same data type
  3. Vectors that are of the same length
  4. Any vector of data type parallel

Que 2. Arrays are faster and more efficient than vectors.

  1. True
  2. False

Que 3. Arrays can be a return type of a function call.

  1. True
  2. False

Que 4. Vectors can be a return type of a function call.

  1. True
  2. False

Upvotes: 1

Views: 1605

Answers (1)

Michael Aaron Safyan
Michael Aaron Safyan

Reputation: 95499

Question 1
The term "parallel vector" is non-standard... (to me, it means that the dot product of their directions is 1!), so you will need to look at your notes and see what the teacher's own meaning of "parallel" is.

Question 2
This is a tricky question. Array construction (of primitives w/o initialization) is faster and more efficient than vector construction (because vectors will initialize their contents). However, if you are just passing around vectors by constant reference and using the subscript operator to access their content then there is no difference in efficiency (those subscript operations are inlined and don't perform any bounds checking). Best ask your teacher, because this is arguably not something that can be presented as a true/false question.

Question 3
Your teacher really likes trick questions, it would seem. No, you cannot return a fixed-sized array from a function; however, you can return an array as a pointer to the first element of a heap-allocated array. Most likely your teacher intends the answer to this question to be false, but the nuances are important.

Question 4
True. This is the only trivial question in this list.

Upvotes: 7

Related Questions