Sie sind auf Seite 1von 5

3/3/2018 C++ Interview Questions and Answers for Freshers, Experienced - Page 2

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

C++ Interview Questions and Answers for Freshers, Experienced


    174 Votes

7. In how many ways we can initialize an int variable in C++?

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;

variable i will get initialized to 10.

Using C++ constructor notation

1. int i(10);

8. What is implicit conversion/coercion in c++?

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.

short a = 2000 + 20;

In the above example, variable a will get automatically promoted from short to int. This is
called implicit conversion/coercion in c++.

9. What are C++ inline functions?

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.

1. inline int min(int a, int b)


2. {
3. return (a < b)? a : b;
4. }
5.  
6. int main( )
7. {
8. cout << "min (20,10): " << min(20,10) << endl;
9. cout << "min (0,200): " << min(0,200) << endl;
10. cout << "min (100,1010): " << min(100,1010) << endl;
11. return 0;
12. }

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. }

10. What do you mean by translation unit in c++?

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

ignored by #ifdef,#ifndef etc)

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.

12. What do you mean by storage classes?

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

Database & SQL Interview Questions


2013-03-02

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

Java Interview Questions


2013-08-13

HR Interview Questions for Freshers


2014-08-24

Popular Videos

How to improve your Interview, Salary Negotiation, Communication & Presentation Skills.

Got a tip or Question?


Let us know

Related Articles
Advanced C Interview Questions and Answers for Experienced

Embedded C Interview Questions and Answers

C Interview Questions and Answers

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

Contribute Projects & Seminars

Report site issue

We're on Social

Facebook

Twitter

Linkedin

YouTube

Google+

Subscribe to our Newsletter

Subscribe to our weekly Newsletter and receive updates via email.

Your email Address...

Subscribe

Copyright © 2016 A4Academics. All rights reserved.

Privacy Policy & Site Terms

About us Contact us Advertise

http://a4academics.com/interview-questions/57-c-plus-plus/419-cpp-interview-questions-answers?showall=&start=1 5/5

Das könnte Ihnen auch gefallen