x

Wednesday, January 27, 2016

Top 99 interview questions and answers for C++| Part 2

Top 99 interview questions and answers for C++| Part 2

C-Interview-Questions-and-Answers-300x204These C++ Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your interview for the subject of C++.

Top 99 interview questions and answers for C++| Part 2

34.

What is operator overloading?

Defining a new job for the existing operator w.r.t the class objects is called as operator overloading.

35.

What is function overloading?

Defining several functions with the same name with unique list of parameters is called as function overloading.

36.

What is the data type to store the Boolean value?

bool, is the new primitive data type introduced in C++ language.

37.

Can we initialize a class/structure member variable as soon as the same is defined?

No, Defining a class/structure is just a type definition and will not allocated memory for the same.

38.

What are/is the operator/operators used to access the class members?

Dot (.) and Arrow ( -> )

39.

Name the data type which can be used to store wide characters in C++

wchar_t

40.

What is a preprocessor?

Preprocessor is a directive to the compiler to perform certain things before the actual compilation process begins.

41.

What is a token?

A C++ program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.

42.

What is a container class?

A class containing at least one member variable of another class type in it is called so.

43.

Where an automatic variable is stored?

Every local variable by default being an auto variable is stored in stack memory

44.

Can a program be compiled without main() function?

Yes, it can be but cannot be executed, as the execution requires main() function definition.

(more…)

45.

When should we use the register storage specifier?

If a variable is used most frequently then it should be declared using register storage specifier, then possibly the compiler gives CPU register for its storage to speed up the look up of the variable.

46.

What is the meaning of base address of the array?

The starting address of the array is called as the base address of the array.

47.

What is the purpose of extern storage specifier.

Used to resolve the scope of global symbol

48.

What is a static variable?

A static local variables retains its value between the function call and the default value is 0. The following function will print 1 2 3 if called thrice. (more…)

49.

What is keyword auto for?

By default every local variable of the function is automatic (auto). In the below function both the variables ‘i’ and ‘j’ are automatic variables. (more…)

50.

How can we catch all kind of exceptions in a single catch block?

The catch block with ellipses as follows

51.

What is a class template?

A template class is a generic class. The keyword template can be used to define a class template.

52.

What are command line arguments?

The arguments/parameters which are sent to the main() function while executing from the command line/console are called so. All the arguments sent are the strings only.

53.

What is a namespace?

A namespace is the logical division of the code which can be used to resolve the name conflict of the identifiers by placing them under different name space.

54.

What is the scope resolution operator?

The scope resolution operator is used to

  • Resolve the scope of global variables.
  • To associate function definition to a class if the function is defined outside the class.

55.

What is the role of the file opening mode ios::trunk?

If the file already exists, its content will be truncated before opening the file.

56.

What is the block scope variable in C++?

A variable whose scope is applicable only within a block is said so. Also a variable in C++ can be declared anywhere within the block.

57.

Can we implement all the concepts of OOPS using the keyword struct?

Yes.

58.

What is the difference between the keywords struct and class in C++?

By default the members of struct are public and by default the members of the class are private.

59.

Explain the pointer – this.

This, is the pointer variable of the compiler which always holds the current active object’s address.

60.

What is function overriding?

Defining the functions within the base and derived class with the same signature and name where the base class’s function is virtual.

61.

Are the exceptions and error same?

No, exceptions can be handled whereas program cannot resolve errors.

62.

What happens if an exception is thrown outside a try block?

The program shall quit abruptly.

63.

Is it legal to assign a base class object to a derived class pointer?

No, it will be error as the compiler fails to do conversion.

64.

Does an abstract class in C++ need to hold all pure virtual functions?

Not necessarily, a class having at least one pure virtual function is abstract class too.

65.

What is the difference between delete and delete[]?

Delete[] is used to release the array allocated memory which was allocated using new[] and delete is used to release one chunk of memory which was allocated using new.

66.

What are available mode of inheritance to inherit one class from another?

Public, private & protected

interviewquiz.net

 

Leave a Reply

No comments:

Post a Comment