Skip to content

Category Archives: C++

In C++, following function declarations cannot be overloaded. 1) Function declarations that differ only in the return type. For example, the following program fails in… Read More
Given a program on fork() system call. #include <stdio.h> #include <unistd.h> int main() {    fork();    fork() && fork() || fork();    fork();       printf("forked\n");    return 0;… Read More
Given below a small piece of code from an open source project, #ifndef __cplusplus    typedef enum BoolenTag {    false,    true } bool;    #endif… Read More
How to swap two variables? The question may look silly, neither geeky. See the following piece of code to swap two integers (XOR swapping), void… Read More
Using result of comma operator as l-value is not valid in C. But in C++, result of comma operator can be used as l-value if… Read More
Difficulty Level: Rookie Consider the following C++ program. #include<iostream>  #include<stdio.h>     using namespace std;     class Test  {      public:      Test() {}      Test(const Test &t)      { … Read More
In C++, this pointer is passed as a hidden argument to all non-static member function calls. The type of this depends upon function declaration. If… Read More
In C++, like other functions, assignement operator function is inherited in derived class. For example, in the following program, base class assignment operator function can… Read More
In C++, a structure is the same as a class except for a few differences. The most important of them is security. A Structure is… Read More
1) static member functions do not have this pointer. For example following program fails in compilation with error “`this’ is unavailable for static member functions “… Read More
In C++ and Java, functions can not be overloaded if they differ only in the return type. For example, the following program C++ and Java… Read More
The order of operands of logical operators &&, || are important in C/C++. In mathematics, logical AND, OR, etc… operations are commutative. The result will… Read More
A nested class is a class which is declared in another enclosing class. A nested class is a member and as such has the same… Read More
The ASCII NUL and zero are represented as 0x00 and 0x30 respectively. An ASCII NUL character serves as sentinel characters of strings in C/C++. When… Read More
Declare “a function with argument of int* which returns pointer to an array of 4 integer pointers”. At the first glance it may look complex, we… Read More