Wednesday, 11 January 2017

C and C++ interview questions and answers

C and C++ interview questions and answers



When is a switch statement better than multiple if statements?

Answer: A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type.

       When is a switch statement better than multiple if statements?

Answer: A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type.

How we can print "Hello World" without using semicolon in c program?

Answer: if we write the printf function inside the if block structure .
e.g. : if (printf("Hello World"));

What printf library function returns?

Answer: printf functions is having int return type which is used to return number
of elements which is printed

Which header file is used to define a function in c programming which can have variable 
number of arguments?
                  Answer: stdarg.h

How we can achieve run time polymorphism in C++?

Answer: we can achieve runtime polymorphism with the use of virtual function in 
base class in C++

What is dangling pointer?

Answer: Dangling pointer is referred to that pointer which points to deallocated 
memory location

Library function which is used to convert string value into int value?

                 Answer: atoi (), the function is defined in header file is stdlib.h

 How the overriding is different than overloading?

Answer: Overriding is achieved using redefine the base class into derived class 
but overloading is achieve using two or more functions with same name and
different arguments

Explain diamond problem of inheritance?

Answer: Diamond problem is ambiguity problem of hybrid inheritance, this 
ambiguity can be resolved using virtual base class

What is significance of argc and argv in command line arguments?

Answer: argc stands for number of arguments including executable filename,
argv stands for argument vector (set of input strings)