-
Pavatharni . S wrote a new item 5 months, 3 weeks ago
public class A { public static void main(String[] args) { if (true) break; } }
-
Pavatharni . S started the topic C++ supports multiple inheritance. in the forum C++ 5 months, 4 weeks ago
It means that we cannot create hybrid inheritance using multiple and hierarchical inheritance.
Let’s consider a simple example. A university has people who are affiliated with it. Some are students, some are faculty members, some are administrators, and so on. So a simple inheritance scheme might have different types of people in different r…[Read more]
-
Pavatharni . S started the topic Explain the volatile and mutable keywords. in the forum C++ 5 months, 4 weeks ago
The volatile keyword informs the compiler that a variable may change without the compiler knowing it. Variables that are declared as volatile will not be cached by the compiler, and will thus always be read from memory.
The mutable keyword can be used for class member variables. Mutable variables are allowed to change from within const member…[Read more]
-
Pavatharni . S started the topic Are you allowed to have a static const member function? Explain your answer. in the forum C++ 5 months, 4 weeks ago
A const member function is one which isn’t allowed to modify the members of the object for which it is called. A static member function is one which can’t be called for a specific object.
Thus, the const modifier for a static member function is meaningless, because there is no object associated with the call.
A more detailed explanation of thi…[Read more]
-
Pavatharni . S started the topic What will be the output of the following program? in the forum C++ 5 months, 4 weeks ago
#include <iostream>
struct A
{
int data[2];A(int x, int y) : data{x, y} {}
virtual void f() {}
};int main(int argc, char **argv)
{
A a(22, 33);int *arr = (int *) &a;
std::cout << arr[2] << std::endl;return 0;
} -
Pavatharni . S started the topic How can a C function be called in a C++ program? in the forum C++ 5 months, 4 weeks ago
Using an extern “C” declaration:
//C code
void func(int i)
{
//code
}void print(int i)
{
//code
} -
Pavatharni . S started the topic What is a storage class? in the forum C++ 5 months, 4 weeks ago
A class that specifies the life and scope of its variables and functions is called a storage class.
In C++ following the storage classes are supported: auto, static, register, extern, and mutable.
Note, however, that the keyword register was deprecated in C++11. In C++17, it was removed and
-
Pavatharni . S started the topic What is the problem with the following code? in the forum C++ 5 months, 4 weeks ago
class A
{
public:
A() {}
~A(){}
};class B: public A
{
public:
B():A(){}
~B(){}
};int main(void)
{
A* a = new B();
delete a;
} -
Pavatharni . S started the topic How can you make sure a C++ function can be called as e.g. void foo(int, int) bu in the forum C++ 5 months, 4 weeks ago
®
24 Essential C++ Interview Questions *
Toptal sourced essential questions that the best C++ developers and engineers can answer. Driven from our community, we encourage experts to submit questions and offer feedback.
Toptal logois an exclusive network of the top freelance software developers, designers, finance experts, product managers, and…[Read more] -
Pavatharni . S started the topic How many times will this loop execute? Explain your answer. in the forum C++ 5 months, 4 weeks ago
unsigned char half_limit = 150;
for (unsigned char i = 0; i < 2 * half_limit; ++i)
{
// do something;
} -
Pavatharni . S started the topic What is the output of the following code: in the forum C++ 5 months, 4 weeks ago
#include <iostream>
class Base {
virtual void method() {std::cout << “from Base” << std::endl;}
public:
virtual ~Base() {method();}
void baseMethod() {method();}
};class A : public Base {
void method() {std::cout << “from A” << std::endl;}
public:
~A() {method();}
};int main(void) {
Base* base = new A;…[Read more] -
Pavatharni . S started the topic What is the output of the following code: in the forum C++ 5 months, 4 weeks ago
#include <iostream>
int main(int argc, const char * argv[]) {
int a[] = {1, 2, 3, 4, 5, 6};
std::cout << (1 + 3)[a] – a[0] + (a + 1)[2];
} -
Pavatharni . S started the topic When you should use virtual inheritance? in the forum C++ 5 months, 4 weeks ago
While it’s ideal to avoid virtual inheritance altogether (you should know how your class is going to be used) having a solid understanding of how virtual inheritance works is still important:
So when you have a class (class A) which inherits from 2 parents (B and C), both of which share a parent (class D), as demonstrated below:
#include &…[Read more]
-
Pavatharni . S started the topic Implement a void function F that takes pointers to two arrays of integers (A and in the forum C++ 5 months, 4 weeks ago
This problem seems easy at first glance so a careless developer might write something like this:
void F(int* A, int* B, int N) {
int m = 1;
for (int i = 0; i < N; ++i) {
m *= A[i];
}for (int i = 0; i < N; ++i) {
B[i] = m / A[i];
}
} -
Pavatharni . S started the topic You are given library class Something as follows: in the forum C++ 5 months, 4 weeks ago
class Something {
public:
Something() {
topSecretValue = 42;
}
bool somePublicBool;
int somePublicInt;
std::string somePublicString;
private:
int topSecretValue;
}; -
Pavatharni . S started the topic What is the output of the following code: in the forum C++ 5 months, 4 weeks ago
#include <iostream>
class A {
public:
A() {}
~A() {
throw 42;
}
};int main(int argc, const char * argv[]) {
try {
A a;
throw 32;
} catch(int a) {
std::cout << a;
}
} -
Pavatharni . S started the topic Is it possible to have a recursive inline function? in the forum C++ 5 months, 4 weeks ago
Although you can call an inline function from within itself, the compiler may not generate inline code since the compiler cannot determine the depth of recursion at compile time. A compiler with a good optimizer can inline recursive calls till some depth fixed at compile-time (say three or five recursive calls), and insert non-recursive calls at…[Read more]
-
Pavatharni . S started the topic Implement a template boolean IsSameClass() that takes class A and B as template in the forum C++ 5 months, 4 weeks ago
template <typename T, typename U>
struct is_same
{
static const bool value = false;
};template <typename T>
struct is_same<T, T>
{
static const bool value = true;
};template <class A, class B>
bool IsSameClass() {
return is_same<A, B>::value;
} -
Pavatharni . S started the topic Implement a template function IsDerivedFrom() that takes class C and class P as in the forum C++ 5 months, 4 weeks ago
This question tests understanding of C++ templates. An experienced developer will know that this is already a part of the C++11 std library (std::is_base_of) or part of the boost library for C++ (boost::is_base_of). Even an interviewee with only passing knowledge should write something similar to this, mostly likely involving a helper…[Read more]
-
Pavatharni . S started the topic Consider the two code snippets below for printing a vector. Is there any advanta in the forum C++ 5 months, 4 weeks ago
vector vec;
/* … .. … */
for (auto itr = vec.begin(); itr != vec.end(); itr++) {
itr->print();
} - Load More