CS253: Software Development with C++

Spring 2020

IQ 03

CS253 IQ 03

Show Main.IQ03 as a slide show.

Parameter Passing

By default, how are scalars, arrays, and objects passed to functions?

  1. scalars by reference, others by value
  2. scalars by value, others by reference
  3. arrays by reference, others by value
  4. arrays by value, others by reference
  5. objects by reference, others by value
  6. objects by value, others by reference

What will this display?

cout << reinterpret_cast<long>("-123");
4196472
  1. the long 123
  2. the long −123
  3. the long 4
  4. the const char * "-123"
  5. none of the above

A C string is terminated by:

  1. a newline
  2. control-D
  3. control-Z
  4. a null character
  5. nullptr
  6. Ahhhnold

A std::string has a maximum length of:

  1. 255
  2. 32767
  3. the maximum value of an int
  4. there is no maximum length
  5. none of the above

How do you get a std::string to work with?

  1. string s;
  2. string s = new string;
  3. new string s;
  4. string s = new string(40); // 40-char string

For any string, which is always true?

string s{"Fluttershy"};
cout << s.capacity() << '\n'
     << s.max_size() << '\n'
     << s.size() << '\n';
15
9223372036854775807
10
  1. .capacity().max_size().size()
  2. .capacity().size().max_size()
  3. .max_size().capacity().size()
  4. .max_size().size().capacity()
  5. .size().capacity().max_size()
  6. .size().max_size().capacity()