Excerpt for Advanced C++ Interview Questions You'll Most Likely Be Asked by , available in its entirety at Smashwords


Advanced C++

Interview Questions

You'll Most Likely Be Asked



Job Interview Questions Series



www.vibrantpublishers.com



*****





Advanced C++ Interview Questions You'll Most Likely Be Asked

Published by Vibrant Publishers at Smashwords

Copyright 2017 Vibrant Publishers, USA.

Smashwords Edition, License Notes

This ebook is licensed for your personal use only. This ebook may not be re-sold or given away to other people. If you would like to share this book with another person, please purchase an additional copy for each recipient. If you’re reading this book and did not purchase it, or it was not purchased for your use only, then please return to Smashwords.com and purchase your own copy. Thank you for respecting the hard work of this author.

This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. The author has made every effort in the preparation of this book to ensure the accuracy of the information. However, information in this book is sold without warranty either expressed or implied. The Author or the Publisher will not be liable for any damages caused or alleged to be caused either directly or indirectly by this book.

Vibrant Publishers books are available at special quantity discount for sales promotions, or for use in corporate training programs. For more information please write to bulkorders@vibrantpublishers.com

Please email feedback / corrections (technical, grammatical or spelling) to spellerrors@vibrantpublishers.com

To access the complete catalogue of Vibrant Publishers, visit www.vibrantpublishers.com



*****





Table of Contents



1. General Concepts

2. Control Statements and Decision Making

3. Functions and Recursion

4. Arrays and Vectors

5. Pointers

6. Control Structures, Array and Pointers

7. Object Oriented Programming and Classes

8. Inheritance, Polymorphism and Virtual Functions

9. Exceptions and Exception Handling

10. Class Template and Standard Template Library (STL)

11. Functions, Class and Template

12. Stream Input Output

13. File Processing

14. Miscellaneous

HR Questions

INDEX



*****





Advanced C++

Interview Questions

You'll Most Likely Be Asked

Review these typical interview questions and think about how you would answer them. Read the answers listed; you will find best possible answers along with strategies and suggestions.



*****





General Concepts



1: Explain Shallow Copy and Deep Copy in C++.

Answer:

When you use the assignment operator to copy an object or array into another, you are actually only copying the pointer of the first object into the other. This is shallow copy. A shallow copy passes on the reference to an object instead of the value stored in it. So when one of the object’s value changes, the change reflects in both, rendering the copy of no use.

Deep copy is when the values are copied instead of the pointer that addresses the object or array. This is done by using an explicit copy constructor. When you use the assignment operator with a complex data type or object, it does only shallow copy.



2: Explain Volatile and Mutable.

Answer:

The Mutable keyword lets you change the value of a constant variable declared using the keyword const. Suppose you have a class and you have declared an object of that class as a const. Usually the const members are not allowed to be changed, unless the member is declared as mutable. The mutable members of a const class can be modified.

The Volatile keyword specifies that the value of the variable may be changed and hence reminds the processor to read or write the value every time it is being used. Volatile variables are not optimized because they should be ready to hold a wide range of values anytime during the program.



3: Explain translation unit in C++.

Answer:

A Translation unit is a single file created to compile a program. It includes the source code, the header files as directed by the #include statements, and any other conditional pre-processing directive as mentioned in the program. If any other program file is accessed by the source code, that file is also included here. All these are made into a single file which is compiled into an executable program, a library or an object file.



4: What is the difference between Static and Extern in C++?

Answer:

Static variables retain the same value across multiple instantiations. If a class has a static variable with a value x, the value will remain the same across all objects of that class. You can access this variable directly using the class name without any object. A static variable can be used across the classes within a program.

The extern keyword is used to create global variables that have scope across programs.



5: What are the preprocessor directives?

Answer:

Preprocessor directives are messages to the preprocessor and are processed before the program is compiled. For example, #include<iostream> tells the C++ preprocessor to include the contents of the iostream header file.



6: What is binary scope resolution operator and why is it used?

Answer:

When a class member function or attribute is defined outside the class, the name of the member function in the function header is preceded by the class name and the binary scope resolution operator (::). Binary scope resolution operator ‘ties’ each member function or data member with the class definition.



7: What is wrong in the following assignment?

char choice;

choice = “y”;

Answer:

Here “y” is a string literal, so cannot be assigned to the character variable ‘choice’. The correct assignment should be:

char choice;

choice = ‘y’;



8: What is the difference between a variable and a literal?

Answer:

Variables represent storage locations in memory, whereas literals are constant values assigned to variables.



9: How many bytes would be required to store ‘\n’?

Answer:

1 byte.



10: Integer literals are expressed in decimal by default. How would you express a hexadecimal number?

Answer:

Hexadecimal numbers are expressed by placing 0x (zero-x) before them. For example, 0xD4.



11: What would be the output of the following program?

#include<iostream>

using namespace std;

int main()

{

char letter;

letter = 66;

cout << letter << endl;

return 0;

}

Answer:

B



12: What would be the output of the following program?

#include<iostream>

using namespace std;

int main()

{

int i;

float f;

f = 8.9;

i = f;

cout << i << endl;

return 0;

}

Answer:

8, when a floating point value is truncated, it is not rounded.



13: Does the size of a data type vary? Which operator could be used for determining the size of a data type on any machine?


Purchase this book or download sample versions for your ebook reader.
(Pages 1-6 show above.)