How Do I Initialize A Const Member?
How Do I Initialize A Const Member?
4. What is C++
C++ is C with classes. It was designed for one person to manage large
amounts of code, and so that a line of C++
express more thing than a line of C. The main functionalities C++
adds to C are:
control of the accessibility to code within the source files (namespace,
struct and class).
mechanisms that make a line of code more expressive (constructors,
destructors, operators, ...).
object programming (class derivation).
generic programming (templates).
5. How do I use namespaces?
void function()
{
void (A::*pm)(int) = &A::m; // pointer on method
A a; // instance of a class
void function()
{
A a;
f(a, &A::m);
}
// ...
A a;
void (*pf)(int);
pf = a.m('a');
void function()
{
void (*psm)(int) = A::sm; // assignment
void (*psm)(int) = &A::sm; // alternative
struct B
{
B() {}
B(const A &a) {}
};
struct C
{
C() {}
explicit C(const A &a) {}
};
void function()
{
A a;
B b;
C c;
fb(a); // ok, conversion is implicit
fc(a); // error
fc(C(a)); // ok, conversion is explicit
}
int function()
{
A::id = 0; // call to a static attribute
return A::gendId(); // call to a static method
}
struct B: public A
{
void f1() { /* ... */ }
};
struct C: public A
{
void f1() { /* ... */ }
void f2() { /* ... */ }
};
class Vector
{
int array[3];
class A
{
template<class> friend class B;
friend class B <class T>;
};
template <>
class Vector <double, 3>
{
double x, y, z;
public:
Vector(const double v): x(v), y(v), z(v) {}
};
std::cin >> f;
std::cin.getline(str, 255);
struct B
{
int b;
B(const int i): b(i) {}
operator A() { return A(b); }
};
// in C // in C++
int i; int i;
int *pi = &i; int &ti = i;
int *pj; int &rj; // g++ refuses to compile that
*pi = 0; ri = 0;
*pj = 0; // segfault rj = 0;
35. Which of the following is evaluated first:
&&
||
!
36. True or false: If you continuously increment a variable, it will become negative?
True
False
It depends on the variable type
Answer: Both A and B
2. Which of the following denote insertion operator in C++?
Answer: <<
3. Which of the following OOPS concepts are used with cin and cout?
Answer: Operator Overloading
4. Pure virtual function in C++ is one in which the virtual function
Answer: has no body
5. The actual implementation is present in
Answer: definition
6. Class that reads and writes to an array in memory is
Answer: strstream
7. cin in C++ program uses the operator
Answer: >>
8. A variable modified by multiple threads should be declared as
Answer: volatile
9. Virtual functions are defined in
Answer: Derived class