Google News
CPP Interview Questions
Some of the operators that cannot be overloaded are as follows :
* Dot operator- “.
* Scope resolution operator- “::
* “sizeof” operator
* Pointer to member operator- “.*
Bool is a data type in C++ which takes two values- True and False. Syntax is as follows:
bool b1 = true;
A sample code is as follows :
using namespace std; 
int main() 
    int a= 4, b= 5; 
    bool c, d; 
    c= a== b; // false 
    c= a< b; // true 
    cout <<b1; 
    cout << b2 ; 
    return 0; 
* C++ supports goto statements whereas Java does not.
* C++ uses a compiler only whereas Java uses both compiler and interpreter.
* C++ supports multiple inheritance whereas Java does not support multiple inheritance
* Java supports unsigned right shift operator (>>>) whereas C++ does not.
* C++ is majorly used in system programming whereas Java is majorly used in application programming.
* C++ supports operator overloading whereas Java does not support operator overloading.
* C++ has pointers which can be used in the program whereas Java has pointers but internally.
* C++ has both call by value and call by reference whereas Java supports only call by value.
* C++ supports structures and joins whereas Java does not support structure and joins
* C++ is interactive with hardware whereas Java is not that interactive with hardware.
The strings in C++ can be concatenated in two ways- one considering them string objects and second concatenating them C style strings.
#include <iostream>
using namespace std;
int main()
    string s_1, s_2, fin;
    cout << "Enter string";
    getline (cin, s_1);
    cout << "Enter string ";
    getline (cin, s_2);
    fin= s_1 + s_2;
    cout << fin;
    char str1[50], str2[50], fin[100];
    cout << "Enter string";
    cin.getline(str1, 50);
    cout << "Enter string";
    cin.getline(str2, 50);
    strcat(str1, str2); 
    cout << "str1 = " << str1 << endl;
    cout << "str2 = " << str2;
    return 0;
To find the absolute value in c++, we can use abs() function. The abs() function in C++ returns the absolute value of an integer number.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
        int a=5.42;
        int x = abs(a);
        cout << x;
            return 0;

Output : 5

An expression is a combination of operators, constants and variables. There seven types of expressions for examples :
* Constant expressions: 89 +10/4.0
* Integral expressions: x * y
* Floating expressions: 17.89
* Relational expressions: a<=b
* Logical expressions: a > b && a == 7
* Pointer expressions: *ptr
* Bitwise expressions: p << 5
The length of a string can be calculated by using in-built functions such as length(), size(), strlen() and also by loops (while and for).
using namespace std;
main() {
   string s = "Free Time Learn";
   char arr[] = "Free Time Learn";
   cout << s.length();
   cout << s.size();
   cout <<strlen(arr);
   char *c = arr;
   int count = 0;
   while(*c != '\0'){
   cout << count;
   count = 0;
   for(int i = 0; arr[i] != '\0'; i++){
   cout << count;

Output : 


A friend function in C++ is defined as a function that can access private, protected and public members of a class.
The friend function is declared using the friend keyword inside the body of the class.
Friend Function Syntax :
class className {
    ... .. ...
    friend returnType functionName(arguments);
    ... .. ...
By using the keyword, the ‘friend’ compiler knows that the given function is a friend function.
We declare friend function inside the body of a class, starting with the keyword friend to access the data. We use them when we need to operate between two different classes at the same time.
C++ compiler encodes the parameter types with function/method into a unique name. This process is called name mangling. The inverse process is called as demangling.
Example :
A::b(int, long) const is mangled as b__C3Ail’.
For a constructor, the method name is left out.
That is A:: A(int, long) const is mangled as C3Ail’.
Class is a blueprint of a project or problem to be solved and consists of variables and methods. These are called the members of the class. We cannot access methods or variables of the class on its own unless they are declared static.
In order to access the class members and put them to use, we should create an instance of a class which is called an Object. The class has an unlimited lifetime whereas an object has a limited lifespan only.