What are the different data types  in C++?

  • By
  • October 1, 2021
  • C & C++
  1. What are the different data types  in C++?

There are 4 data types in C++  :

 

(basic data type). Ex – char, short, int, float, long, double, bool, etc.

Derived datatype. Example – array, pointer, etc.

Enumeration  Example- enum

User-defined data types.  Example – structure, class, etc

 

  1. What are class and object in C++ ?

A class is a data type derived by a user that has data members and member functions. Data members are the variables and member functions are the functions which are used to perform operations on these variables.

For Free, Demo classes Call: 8237077325
Registration Link: Click Here!

 

An object is an instance of a class. Since a class is a  data type derived by user so an object can also be called a variable of that data type. Read more at C and C++ Training in Pune

 

  1. What is operator overloading ?

Operator Overloading is a very important element to perform the operations on user-defined data types. By operator overloading C and C++ Classes in Pune can change the default meaning to the operators like +, -, *, /, 

 

  1. What is polymorphism in Cpp ?

Polymorphism in simple words having many forms. Its behavior is different in different situations. And this happens when C and C++ Course in Pune have multiple classes which are related to each other by inheritance.

 

For ex, think of a base class called a car that has a method called car(). Derived classes of cars could be Ford, Rolls-Royce, Bently – And they also have their own implementation of a cars

 

The two types of polymorphism in Cpp are:

 

Compile Time Polymorphism (method overloading)

Runtime Polymorphism (method overriding)

 

  1. Explain constructor in Cpp

The constructor is nothing but the special type of method .It is used to initialize the state of an object. The name of the constructor should  be the same as the class name. It is invoked when the class is instantiated or an object is  to be created.  The constructor does not have a return type.

Default Constructor: 

that the constructors which can not accept the arguments are called Default constructors.

It is mostly used to initialize the instance variable with the default values.

if there is constructor is not defined in the class.A default constructor is invoked implicitly by the compiler

Parameterized Constructor:

  the constructor where can pass the parameter the 

or we can say the constructor which can accept the arguments are called parameterized constructors.

 

Copy Constructor :

Value of One object can copy into another object  is call Copy Constructor.

For Free, Demo classes Call: 8237077325
Registration Link: Click Here!

 

 

  1. Tell me about virtual function

Virtual function is a member function in the base class that we redefine in a derived class. A virtual function can be declared using the virtual keyword. When the function is defined virtual, Cpp  determines which function is to be invoked at the runtime based on the type of the object pointed by the base class pointer

 

  1. What do you know about friend class and friend function?

A friend class can access private, protected, and public members of other classes in which it is declared as friend.

 

As friend class, friend function can also access private, protected, and public members. But, the Friend function is not a member function.

 

  1. What are the access specifiers in Cpp?

In Cpp there are the three access specifiers:

 

Public: All data members and member functions can be accessible outside the class.

 

Protected: All data members and member functions can be accessible inside the class and to the derived class.

 

Private: All data members and member functions can not be accessible outside the class.

 

  1. Define inheritance with a real life example?

It is one process that can be defined as an object having all the properties and behaviour of its parents object is called inheritance.

Eg:- child and parent 

 

  1. What is pointer ?Define null pointer?

 Pointer can be defined as a variable used to store address of another variable.A null pointer is a pointer which do  not point to any memory location is called null pointer.

13.What is dangling pointer?

When one pointer points to a memory location but meanwhile other pointer deletes that memory then first pointer is called a dangling pointer.

For Free, Demo classes Call: 8237077325
Registration Link: Click Here!

 

 

  1. Can we compile the program witohut main function ?

Yes

 

  1. constructor is or not inherited?

 The constructor is not inherited.

 

  1. Can we make a final constructor ?

 the constructor can not  be final.

  1. What are destructors in C++?

when an object is destroyed a function called destructor automatically same like  A constructor .constructor  is automatically called when an object is first created. . A destructor has the same name as class  (which is the same as the clconstructor name) .it  is preceded by a tilde(~).

 

  1. What is the size of void in C++?

size of void is 0.

20.What are void pointers?

A void pointer is a pointer which does not have any datatype . It hold addresses of any type.

Author:-

Ghodekar, Pooja

Call the Trainer and Book your free demo class for now!!!

© Copyright 2020 | Sevenmentor Pvt Ltd.

Submit Comment

Your email address will not be published.

*
*