CS253 IQ 02
Show Main.IQ02 as a slide show.
Bit Manipulation
What’s the best way to find out if bit #7 (where bit #0 is the LSB)
of the int v
is set?
if (v.bit(7))
if (v & 00000080)
if (v && (1 << 7))
if ((v>>7) & 01)
if ((v<<24) < 0)
Which is undefined behavior?
printf("%d\n", 42);
cout << sizeof(long double);
- Whether
f()
or g()
is called first in h = f() + g();
a = b++ + b;
Difference between '\n'
and endl
?
'\n'
is exactly ASCII newline, whereas endl
is
platform dependent, e.g., CR/LF on Windows.
- No difference—
endl
is simply for code readability.
endl
also works for terminating a string with '\0'
.
endl
flushes the output, '\n'
does not.
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;
}
a
is in data, b
is on the heap, c
points to the stack
a
is in data, b
is on the stack, c
points to the heap
a
is on the heap, b
is in data, c
points to the stack
a
is on the heap, b
is on the stack, c
points to data
a
is on the stack, b
is in data, c
points to the heap
a
is on the stack, b
is on the heap, c
points to data
Which statement is true?
#include <iostream>
puts cout
into the std
namespace.
#include <iostream>
puts cout
into the global namespace.
- Both of the above.
#include <iostream.h>
puts cout
into the global namespace.
- None of the above.
Difference between const
and constexpr
?
const
is for methods, constexpr
for values.
const
says that you can’t change it,
constexpr
says that it doesn’t change.
const
is compile-time constancy, constexpr
is run-time constancy.
const
is for the data segment, constexpr
is for the stack or heap.
const
is C, constexpr
is C++.