CS253: Software Development with C++

Fall 2018

IQ 02

CS253 IQ 02

See this page as a slide show

Which is undefined behavior?

  1. printf("%d\n", 42);
  2. cout << sizeof(long double);
  3. Whether f() or g() is called first in h = f() + g();
  4. a = b++ + b;

Difference between '\n' and endl?

  1. '\n' is exactly ASCII newline, whereas endl is platform dependent, e.g., CR/LF on Windows.
  2. No difference—endl is simply for code readability.
  3. endl also works for terminating a string with '\0'.
  4. endl flushes the output, '\n' does not.
  5. endl takes an optional argument for multiple blank lines: endl(4)

Which is true?

int a=1;
int main() {
    int b=2;
    int *c = new int;
}
  1. a is in data, b is on the heap, c points to the stack
  2. a is in data, b is on the stack, c points to the heap
  3. a is on the heap, b is in data, c points to the stack
  4. a is on the heap, b is on the stack, c points to data
  5. a is on the stack, b is in data, c points to the heap
  6. a is on the stack, b is on the heap, c points to data

Which statement is true?

  1. #include <iostream> puts cout into the std namespace.
  2. #include <iostream> puts cout into the global namespace.
  3. Both of the above.
  4. #include <iostream.h> puts cout into the global namespace.
  5. None of the above.

Difference between const and constexpr?

  1. const is for methods, constexpr for values.
  2. const says that you can’t change it, constexpr says that it doesn’t change.
  3. const is compile-time constancy, constexpr is run-time constancy.
  4. const is for the data segment, constexpr is for the stack or heap.
  5. const is C, constexpr is C++.

User: Guest

Check: HTML CSS
Edit History Source

Modified: 2018-07-01T12:30

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building