CS253: Software Development with C++

Fall 2018

IQ 04

CS253 IQ 04

See this page as a slide show

What will this code display?

auto foo = "123456789";
cout << foo.size();
c.cc:2: error: request for member 'size' in 'foo', which is of non-class type 
   'const char*'
  1. 4
  2. 8
  3. 9
  4. 10
  5. None of the above.

What will this different code display?

auto foo = "123456789";
cout << sizeof(foo);
8
  1. 4
  2. 8
  3. 9
  4. 10
  5. None of the above.

What will this code display?

for (int i=0; i<2; i++) {
    cout << "α ";
    static auto &foo = (cout << "β ");
    foo << "γ ";
}
α β γ α γ 
  1. α β γ α β γ
  2. α β γ α γ
  3. α γ α γ
  4. β α γ α γ
  5. None of the above.

What’s the difference?

  1. struct is for C programs, class for C++ programs.
  2. class can have methods, struct can’t.
  3. struct defaults to public, class defaults to private.
  4. classes are automatically friends, structs are not.
  5. They are exactly the same.

Friends

class Witch wants to access class Vision’s private data.

  1. Put friend Vision Witch; outside of either class.
  2. Put friend Witch Vision; outside of either class.
  3. Put friend class Witch; inside Vision.
  4. Put friend class Vision; inside Witch.
  5. Make Witch a nested class within class Vision.

User: Guest

Check: HTML CSS
Edit History Source

Modified: 2018-07-11T13:15

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