C++ Interview Answers

3 min
3
0
0
Published on updated on
  1. What is the difference between C & C++?

    C makes use of structures, function concepts, pre-processor statements, pointer and some build in function etc. to develop application and program.Where as C++ is superset of C and has more object based concepts such as class, overloading, Inheritance, polymorphism etc. apart from mentioned earlier C concepts, which gives more flexibility in developing object oriented application/GUI/CGI etc

  2. What is the difference between an object and a class?

    Classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects. A Class is static. All of the attributes of a class are fixed before, during, and after the execution of a program. The attributes of a class don't change. The class to which an object belongs is also (usually) static. If a particular object belongs to a certain class at the time that it is created then it almost certainly will still belong to that class right up until the time that it is destroyed. An Object on the other hand has a limited lifespan. Objects are created and eventually destroyed. Also during that lifetime, the attributes of the object may undergo significant change.

  3. What is abstraction?

    It is a process to identify the relevant characteristic of a class. The objective of abstraction is to isolate those aspects that are important for some purpose and suppress those that are not important.

  4. What is the difference between "C structure" and "C++ structure"?

    C structures contain only data members where as C++ structure contains both data members and member functions as well.

  5. What is the use of virtual destructor?

    Its always better to have a virtual destructor in a class which has got virtual functions. When an object is created with instantiating the derived class like [baseclass* bclass = new derivedclass] when you delete the base class pointer it calls the derived class destructor also so it leaves no chance for memory leak.

  6. What is the difference between macro and inline()?

    Inline functions are similar to macros because they both are expanded at compile time, but the macros are expanded by the pre-processor, while inline functions are parsed by the compiler. There are several important differences: · Inline functions follow all the protocols of type safety enforced on normal functions. · Inline functions are specified using the same syntax as any other function except that they include the inline keyword in the function declaration. · Expressions passed as arguments to inline functions are evaluated once. In some cases, expressions passed as arguments to macros can be evaluated more than once.

  7. Difference between realloc() and free()?

    The free subroutine frees a block of memory previously allocated by the malloc subroutine. Undefined results occur if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null value, no action will occur. The realloc subroutine changes the size of the block of memory pointed to by the Pointer parameter to the number of bytes specified by the Size parameter and returns a new pointer to the block. The pointer specified by the Pointer parameter must have been created with the malloc, calloc, or realloc subroutines and not been deallocated with the free or realloc subroutines. Undefined results occur if the Pointer parameter is not a valid pointer.

  8. What is public, protected, private?

    Public, protected and private are three access specifiers in C++. Public data members and member functions are accessible outside the class. Protected data members and member functions are only available to derived classes. Private data members and member functions can’t be accessed outside the class. However there is an exception can be using friend classes.

  9. What is encapsulation?

    Classes in C++ provide static encapsulation of objects, by generating code which contains specific knowledge about the internals of encapsulated objects. Static encapsulation occurs at compile time, and therefore cannot directly support the evolution of objects, since recompilation of source code is required if the internal layout changes. This also prohibits the use of distributed or persistent objects without first ensuring that the internal representations of the objects match the ones in the compiled code

  10. What is difference between inline function and ordinary function?

    The difference between an inline and a regular function is that instead of calling the function, the compiler copies the function on the spot.

Click on the link to search and apply for C++ jobs

Answers sourced from www.geekinterview.com

 

Continue reading around the topics :

Comment

In the same category

free entry-level IT courses IT Career Advice
Whether you’re looking to switch careers or dive into IT straight from school, you can pick up the essential skills without breaking the bank. We're sharing free resources and answering common questions that can guide you on your journey.
4 min

Connecting Tech-Talent

Free-Work, THE platform for all IT professionals.

Free-workers
Resources
About
Recruiters area
2024 © Free-Work / AGSI SAS
Follow us