Professional Documents
Culture Documents
C++InterviewQuestionsandAnswersfor
Freshers,ExperiencedPage2
174Votes LastUpdated:22November2014Hits:88386
7.InhowmanywayswecaninitializeanintvariableinC++?
Inc++,variablescanbeinitializedintwoways,thetraditionalC++initializationusing
"="operatorandsecondusingtheconstructornotation.
TraditionalC++initilization
1. inti=10
variableiwillgetinitializedto10.
UsingC++constructornotation
1. inti(10)
8.Whatisimplicitconversion/coercioninc++?
OfficialHPOnlineStore
BuyHPOriginalInkCartridges.FreeSameDayDelivery.PayCOD.
Implicitconversionsareperformedwhenatype(sayT)isusedinacontextwherea
compatibletype(SayF)isexpectedsothatthetypeTwillbepromotedtotypeF.
shorta=2000+20
http://a4academics.com/interviewquestions/57cplusplus/419cppinterviewquestionsanswers?showall=&start=1 1/6
19/04/2015 C++InterviewQuestionsandAnswersforFreshers,ExperiencedPage2
Intheaboveexample,variableawillgetautomaticallypromotedfromshorttoint.This
iscalledimplicitconversion/coercioninc++.
9.WhatareC++inlinefunctions?
C++inlinefunctionsarespecialfunctions,forwhichthecompilerreplacesthefunction
callwithbody/definitionoffunction.Inlinefunctionsmakestheprogramexecutefaster
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 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
compilertomakeitinline,whichcompilermayignore.So,pleasenotethispointfor
theinterviewthat,itisuptothecompilertomakeafunctioninlineornot.
1. inlineintmin(inta,intb)
2. {
3. return(a<b)?a:b
4. }
5.
6. intmain()
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. return0
http://a4academics.com/interviewquestions/57cplusplus/419cppinterviewquestionsanswers?showall=&start=1 2/6
19/04/2015 C++InterviewQuestionsandAnswersforFreshers,ExperiencedPage2
12. }
Ifthecomplierdecidestomakethefunctionminasinline,thentheabovecodewill
internallylookasifitwaswrittenlike
1. intmain()
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. return0
7. }
10.Whatdoyoumeanbytranslationunitinc++?
WeorganizeourC++programsintodifferentsourcefiles(.cpp,.cxxetc).Whenyou
considerasourcefile,atthepreprocessingstage,someextracontentmaygetadded
to the source code ( for example, the contents of header files included) and some
contentmaygetremoved(forexample,thepartofthecodeinthe#ifdefof#ifndef
blockwhichresolvetofalse/0basedonthesymbolsdefined).Thiseffectivecontentis
calledatranslationunit.Inotherwords,atranslationunitconsistsof
Contentsofsourcefile
Pluscontentsoffilesincludeddirectlyorindirectly
Minussourcecodelinesignoredbyanyconditionalpreprocessingdirectives(
thelinesignoredby#ifdef,#ifndefetc)
11.Whatdoyoumeanbyinternallinkingandexternallinkinginc++?
[Thisinterviewquestionisrelatedtoquestionson"translationunit"and"storageclasses"]
Asymbolissaidtobelinkedinternallywhenitcanbeaccessedonlyfromwithinthe
scopeofasingletranslationunit.Byexternallinkingasymbolcanbeaccessedfrom
other translation units as well. This linkage can be controlled by using static and
externkeywords.
12.Whatdoyoumeanbystorageclasses?
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
http://a4academics.com/interviewquestions/57cplusplus/419cppinterviewquestionsanswers?showall=&start=1 3/6
19/04/2015 C++InterviewQuestionsandAnswersforFreshers,ExperiencedPage2
availableduringtheexecutionofprogram.
Completed12th?
GetparttimecoursesinAnimationJoinArenaalongwithcollege
Pages 1 2 3 4
ConnectWithUs
WriteforUsandGetPaid
PopularPosts
HRInterviewQuestionsandAnswers
DatabaseandSQLInterviewQuestionsandAnswersforFreshers,Experienced
SQLQueryInterviewQuestionsandAnswerswithExamples
JavaInterviewQuestionsandAnswers
CareersChoicesandJobOpportunitiesforElectronicsandCommunicationEngineers
AdsbyGoogle
C++PDF
C++InterviewQuestions
C++OOP
StudentPrograms&Deals
WanttostudyinthetopUSuniversities?
GetinfoaboutTopUSColleges
RelatedArticles
http://a4academics.com/interviewquestions/57cplusplus/419cppinterviewquestionsanswers?showall=&start=1 4/6
19/04/2015 C++InterviewQuestionsandAnswersforFreshers,ExperiencedPage2
CInterviewQuestionsandAnswersforExperienced
EmbeddedCInterviewQuestionsandAnswers
CInterviewQuestionsandAnswersforFreshers
C#OOPSInterviewQuestionsandAnswers
.NetFrameworkInterviewQuestionsandAnswers
ADO.NetInterviewQuestionsandAnswersforFreshers,Experienced
ASP.NetInterviewQuestionsandAnswers
ASP.NetMVCInterviewquestionsandAnswers
WCFInterviewQuestionsandAnswers
ASP.NetWebAPIInterviewQuestions
Top80+SQLQueryInterviewQuestionsandAnswerswithExamples
Database/SQLInterviewQuestionsandAnswersforFreshers,Experienced
OracleInterviewQuestionsandAnswersonSQLQueriesandDatabaseTheory
AdvancedSQLInterviewQuestionsandAnswers
EmailNewsletter
EnteryourEmailAddressandgetinterestingupdates
YouremailAddress... Subscribe
QuestionsandAnswersforFreshers,Experienced
QuickLinks
Home
B.EProjects
CareersJobs
Tutorials
InterviewQuestions
Blog
PlacementTest
Forum
SeminarTopics
ContributeProjects&Seminars
QuickContacts Followuson
E:info@a4academics.com
W:www.a4academics.com
http://a4academics.com/interviewquestions/57cplusplus/419cppinterviewquestionsanswers?showall=&start=1 5/6
19/04/2015 C++InterviewQuestionsandAnswersforFreshers,ExperiencedPage2
Copyright2014A4Academics.Allrightsreserved. Privacy&TermsAboutUsContactUsAdvertise
http://a4academics.com/interviewquestions/57cplusplus/419cppinterviewquestionsanswers?showall=&start=1 6/6