Beruflich Dokumente
Kultur Dokumente
About us Contact us
You are here: Home > Interview Questions > C and C++ Interview Questions and Answers > C++ Interview Questions and
Answers for Freshers, Experienced
In c++, variables can be initialized in two ways, the traditional C++ initialization using "="
operator and second using the constructor notation.
Traditional C++ initilization
1. int i = 10;
1. int i(10);
Implicit conversions are performed when a type (say T) is used in a context where a
compatible type (Say F) is expected so that the type T will be promoted to type F.
In the above example, variable a will get automatically promoted from short to int. This is
called implicit conversion/coercion in c++.
C++ inline functions are special functions, for which the compiler replaces the function call
with body/de nition of function. Inline functions makes the program execute faster than the
normal functions, since the overhead involved in saving current state to stack on the
function call is avoided. By giving developer the control of making a function as inline, he can
further optimize the code based on application logic. But actually, it's the compiler that
d id h h k f i i li dl fi' d l
http://a4academics.com/interview-questions/57-c-plus-plus/419-cpp-interview-questions-answers?showall=&start=1 i C il 1/5
3/3/2018 C++ Interview Questions and Answers for Freshers, Experienced - Page 2
decides whether to make a function inline or not regardless of it's declaration. Compiler may
choose to make a non inline function inline and vice versa. Declaring a function as inline is in
effect a request to the compiler to make it inline, which compiler may ignore. So, please note
this point for the interview that, it is upto the compiler to make a function inline or not.
If the complier decides to make the function min as inline, then the above code will internally
look as if it was written like
1. int main( )
2. {
3. cout << "min (20,10): " << ((20 < 10)? 20 : 10) << endl;
4. cout << "min (0,200): " << ((0 < 200)? 0 : 200) << endl;
5. cout << "min (100,1010): " << ((100 < 1010)? 100 : 1010) << endl;
6. return 0;
7. }
We organize our C++ programs into different source les (.cpp, .cxx etc). When you consider
a source le, at the preprocessing stage, some extra content may get added to the source
code ( for example, the contents of header les included) and some content may get
removed ( for example, the part of the code in the #ifdef of #ifndef block which resolve to
false/0 based on the symbols de ned). This effective content is called a translation unit. In
other words, a translation unit consists of
Contents of source le
Plus contents of les included directly or indirectly
Minus source code lines ignored by any conditional pre processing directives ( the lines
http://a4academics.com/interview-questions/57-c-plus-plus/419-cpp-interview-questions-answers?showall=&start=1 2/5
3/3/2018 C++ Interview Questions and Answers for Freshers, Experienced - Page 2
11. What do you mean by internal linking and external linking in c++?
[This interview question is related to questions on "translation unit" and "storage classes"]
A symbol is said to be linked internally when it can be accessed only from with-in the scope
of a single translation unit. By external linking a symbol can be accessed from other
translation units as well. This linkage can be controlled by using static and extern keywords.
Storage class are used to specify the visibility/scope and life time of symbols(functions and
variables). That means, storage classes specify where all a variable or function can be
accessed and till what time those variables will be available during the execution of program.
Page 2 of 4
Pages 1 2 3 4
New Articles
Best Job interview tips to land you in your dream job
2015-08-09
Popular Articles
SQL Queries Interview Questions and Answers
2013-02-26
C# Interview Questions
2013-03-17
http://a4academics.com/interview-questions/57-c-plus-plus/419-cpp-interview-questions-answers?showall=&start=1 3/5
3/3/2018 C++ Interview Questions and Answers for Freshers, Experienced - Page 2
Popular Videos
How to improve your Interview, Salary Negotiation, Communication & Presentation Skills.
Related Articles
Advanced C Interview Questions and Answers for Experienced
Site Links
Careers Jobs
http://a4academics.com/interview-questions/57-c-plus-plus/419-cpp-interview-questions-answers?showall=&start=1 4/5
3/3/2018 C++ Interview Questions and Answers for Freshers, Experienced - Page 2
Interview Questions
Placement Test
Seminar Topics
B.E Projects
Community
Write for us
Blog
Forum
We're on Social
YouTube
Google+
Subscribe
http://a4academics.com/interview-questions/57-c-plus-plus/419-cpp-interview-questions-answers?showall=&start=1 5/5