April 29, 2013

C/C++ Programming interview questions and answers

Can you think of a situation where your program would crash without reaching the breakpoint which you set at the beginning of main()?
Ans- C++ allows for dynamic initialization of global variables before main() is invoked. It is possible that initialization of global will invoke some function. If this function crashes the crash will occur before main() is entered.



Name two cases where you MUST use initialization list as opposed to assignment in constructors.
Ans- Both non-static const data members and reference data members cannot be assigned values; instead, you should use initialization list to initialize them.



Can you overload a function based only on whether a parameter is a value or a reference?
Ans- No. Passing by value and by reference looks identical to the caller.



What are the differences between a C++ struct and C++ class?
Ans- The default member and base class access specifiers are different.
The C++ struct has all the features of the class. The only differences are that a struct defaults to public member access and public base class inheritance, and a class defaults to the private access specifier and private base class inheritance.



What does extern "C" int func(int *, Foo) accomplish?
Ans- It will turn off "name mangling" for func so that one can link to code compiled by a C compiler.



How do you access the static member of a class?
Ans- <ClassName>::<StaticMemberName>

1 comment:

  • Blogger news

    This Blog Contains All Topics Related To Internet, Website Help, Interview Questions, News, Results From Various Resources, Visit Daily For More Interesting And Famous Topics.
  • Random Post

  • About

    We Provide All Information Which you Needed. We Maintain This Blog Very Carefully, If You Find Any Mistake or Any Suggestions Then Please Let Us Know, You Can Contact Us By Comments, On FB Page Or On Google+ Page. ~ Thank You