嵌入式面试问题及解答英文Word格式文档下载.docx

上传人:b****6 文档编号:17514817 上传时间:2022-12-06 格式:DOCX 页数:13 大小:20.21KB
下载 相关 举报
嵌入式面试问题及解答英文Word格式文档下载.docx_第1页
第1页 / 共13页
嵌入式面试问题及解答英文Word格式文档下载.docx_第2页
第2页 / 共13页
嵌入式面试问题及解答英文Word格式文档下载.docx_第3页
第3页 / 共13页
嵌入式面试问题及解答英文Word格式文档下载.docx_第4页
第4页 / 共13页
嵌入式面试问题及解答英文Word格式文档下载.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

嵌入式面试问题及解答英文Word格式文档下载.docx

《嵌入式面试问题及解答英文Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《嵌入式面试问题及解答英文Word格式文档下载.docx(13页珍藏版)》请在冰豆网上搜索。

嵌入式面试问题及解答英文Word格式文档下载.docx

{

c5=c4=analysis;

++c4;

c3=&

analysis[6];

c2=c5+2;

c1=&

analysis[7]-3;

printf("

%c\t%c\t%c\t%c\t%c"

*c1,*c2,*c3,*c4,*c5);

return0;

}

c1,c2,c3,c4andc5arepointers(whichcanholdaddresses).

analysisisanarrayvariablewhichisholdingthestring"

analysis"

.

>

Thestartingaddressofthearrayisgiventoc5andc4.Hencetheypointtofirstcharacter'

inthearray.

c4isincrementedby1.Hencepointsto'

c3isgiventheaddressof7thcharacter(countfrom0)ofthearray.Hencec3pointstocharacter'

c5pointstofirstcharacter.plus2means,c2pointsto3rdcharacter'

(second'

inthestring).

c1pointsto3rdcharacterfromtheend(notcountingthelastcharacter).

c1holdstheaddress.*c1meansthedatastroredatc1.Sincec1pointsto3rdcharacterfromtheend(thatis5thcharacter-countstartsfrom0),*choldscharacter'

Hence*c1willprint'

onthescreen.

Similarlyforotherpointervariables*c2,*c3,*c4and*c5

3.

a=5b=10c=7

(a>

c)?

a:

((b>

b:

c)

Answer:

10

4

Question:

HowdoyoudeclareanarrayofNpointerstofunctionsreturning

pointerstofunctionsreturningpointerstocharacters?

A.char*(*(*a[N])())();

B.Buildthedeclarationupincrementally,usingtypedefs:

C.Usethecdeclprogram,whichturnsEnglishintoCandvice

versa:

D.Alloftheabove.

Answer:

D

5

voidmain()

{

intcount=10,*temp,sum=0;

temp=&

count;

*temp=20;

sum;

*temp=count;

printf("

%d%d%d"

count,*temp,sum);

}

Answer:

20;

6

inti=7;

%d"

i++*i++);

49.

Note:

Don’tchangeavariabletwiceinoneexpression.

7

Thenumberofsyntaxerrorsintheprogram?

intf()

f

(1);

f(1,2);

f(1,2,3);

f(inti,intj,intk)

%d%d%d"

i,j,k);

None.

8

voidmain()

floatj;

j=1000*1000;

%f"

j);

A.1000000

B.Overflow

C.Error

D.Noneoftheabove

9

Givetheoutputoftheprogram

unsignedi=1;

/*unsignedchark=-1=>

k=255;

*/

signedj=-1;

/*chark=-1=>

k=65535*/

/*unsignedorsignedintk=-1=>

k=65535*/

if(i<

j)

less"

);

else

if(i>

greater"

if(i==j)

equal"

less

10

Givetheoutputoftheprogram

char*s="

12345sn"

;

sizeof(s));

4

11

inti;

for(i=1;

i<

4,i++)

switch(i)

case1:

printf("

i);

break;

case2:

case3:

switch(i)case4:

1,2,3,4

12.

Howtopasstwoargumentstoafunctionpromptedtobyfunctionpointer

A.g->

(1,2)

B.*g(1,2)

C.(*g)(1,2)

D.g(1,2)

C

13

Canyouhaveconstantvolatilevariable?

YES.Wecanhaveaconstvolatilevariable.

avolatilevariableisavariablewhichcanbechangedbytheextrenalevents(likeaninterrputtimerswillincrementthevoltilevarible.Ifyoudontwantyouvolatilevaribaletobechangedthendeclarethemas“constvolatile”.

14.

studythecode:

#include<

stdio.h>

constinta=100;

int*p;

p=&

a;

(*p)++;

a=%d\n(*p)=%d\n"

a,*p);

Whatisprinted?

A)100,101B)100,100C)101,101D)Noneoftheabove

AnswerC

EmbeddedC

1.Usingthe#definestatement,howwouldyoudeclareamanifestconstantthatreturnsthenumberofsecondsinayear?

Disregardleapyearsinyouranswer.

#defineSECONDS_PER_YEAR(60*60*24*365)UL

I'

mlookingforseveralthingshere:

Basicknowledgeofthe#definesyntax(forexample,nosemi-colonattheend,theneedtoparenthesize,andsoon)

Anunderstandingthatthepre-processorwillevaluateconstantexpressionsforyou.Thus,itisclearer,andpenalty-free,tospellouthowyouarecalculatingthenumberofsecondsinayear,ratherthanactuallydoingthecalculationyourself

Arealizationthattheexpressionwilloverflowanintegerargumentona16-bitmachine-hencetheneedfortheL,tellingthecompilertotreatthevariableasaLong

Asabonus,ifyoumodifiedtheexpressionwithaUL(indicatingunsignedlong),thenyouareofftoagreatstart.Andremember,firstimpressionscount!

2.Writethe"

standard"

MINmacro-thatis,amacrothattakestwoargumentsandreturnsthesmallerofthetwoarguments.

#defineMIN(A,B)((A)<

=(B)?

(A):

(B))

Thepurposeofthisquestionistotestthefollowing:

Basicknowledgeofthe#definedirectiveasusedinmacros.ThisisimportantbecauseuntiltheinlineoperatorbecomespartofstandardC,macrosaretheonlyportablewayofgeneratinginlinecode.Inlinecodeisoftennecessaryinembeddedsystemsinordertoachievetherequiredperformancelevel

Knowledgeoftheternaryconditionaloperator.ThisoperatorexistsinCbecauseitallowsthecompilertoproducemoreoptimalcodethananif-then-elsesequence.Giventhatperformanceisnormallyanissueinembeddedsystems,knowledgeanduseofthisconstructisimportant

Understandingoftheneedtoverycarefullyparenthesizeargumentstomacros

Ialsousethisquestiontostartadiscussiononthesideeffectsofmacros,forexample,whathappenswhenyouwritecodesuchas:

least=MIN(*p++,b);

3.Infiniteloopsoftenariseinembeddedsystems.HowdoesyoucodeaninfiniteloopinC?

Thereareseveralsolutionstothisquestion.Mypreferredsolutionis:

while

(1)

?

5.Usingthevariablea,givedefinitionsforthefollowing:

a)Aninteger

b)Apointertoaninteger

c)Apointertoapointertoaninteger

d)Anarrayof10integers

e)Anarrayof10pointerstointegers

f)Apointertoanarrayof10integers

g)Apointertoafunctionthattakesanintegerasanargumentandreturnsaninteger

h)Anarrayoftenpointerstofunctionsthattakeanintegerargumentandreturnaninteger

Answers:

a)inta;

//Aninteger

b)int*a;

//Apointertoaninteger

c)int**a;

//Apointertoapointertoaninteger

d)inta[10];

//Anarrayof10integers

e)int*a[10];

//Anarrayof10pointerstointegers

f)int(*a)[10];

//Apointertoanarrayof10integers

g)int(*a)(int);

//Apointertoafunctionathattakesanintegerargumentandreturnsaninteger

h)int(*a[10])(int);

//Anarrayof10pointerstofunctionsthattakeanintegerargumentandreturnaninteger

Peopleoftenclaimthatacoupleofthesearethesortsofthingthatonelooksupintextbooks-andIagree.Whilewritingthisarticle,Iconsultedtextbookstoensurethesyntaxwascorrect.However,Iexpecttobeaskedthisquestion(orsomethingclosetoit)whenI'

mbeinginterviewed.Consequently,ImakesureIknowtheanswers,atleastforthefewhoursoftheinterview.Candidateswhodon'

tknowalltheanswers(oratleastmostofthem)aresimplyunpreparedfortheinterview.Iftheycan'

tbepreparedfortheinterview,whatwilltheybepreparedfor?

6.Whataretheusesofthekeywordstatic?

StatichasthreedistinctusesinC:

Avariabledeclaredstaticwithinthebodyofafunctionmaintainsitsvaluebetweenfunctioninvocations

Avariabledeclaredstaticwithinamodule,(butoutsidethebodyofafunction)isaccessiblebyallfunctionswithinthatmodule.Itisnotaccessiblebyfunctionswithinanyothermodule.Thatis,itisalocalizedglobal

Functionsdeclaredstaticwithinamodulemayonlybecalledbyotherfunctionswithinthatmodule.Thatis,thescopeofthefunctionislocalizedtothemodulewithinwhichitisdeclared

Mostcandidatesgetthefirstpartcorrect.Areasonablenumbergetthesecondpartcorrect,whileapitifulnumberunderstandthethirdanswer.Thisisaseriousweaknessinacandidate,sinceheobviouslydoesn'

tunderstandtheimportanceandbenefitsoflocalizingthescopeofbothdataandcode.

7.Whatdothefollowingdeclarationsmean?

constinta;

intconsta;

constint*a;

int*consta;

intconst*consta;

Answer

Thefirsttwomeanthesamething,namelyaisaconst(read-only)integer.Thethirdmeansaisapointertoaconstinteger(thatis,theintegerisn'

tmodifiable,butthepointeris).Thefourthdeclaresatobeaconstpointertoaninteger(thatis,theintegerpointedtobyaismodifiable,butthepointerisnot).Thefinaldeclarationdeclaresatobeaconstpointertoaconstinteger(thatis,neithertheintegerpointedtobya,northepointeritselfmaybemodified).

8.Whatdoesthekeywordvolatilemean?

Givethreedifferentexamplesofitsuse.

Avolatilevariableisonethatcanchangeunexpectedly.Consequently,thecompilercanmakenoassumptionsaboutthevalueofthevariable.Inparticular,theoptimizermustbecarefultoreloadthevariableeverytimeitisusedinsteadofholdingacopyinaregister.Examplesofvolatilevariablesare:

Hardwareregistersinperipherals(forexample,statusregisters)

Non-automaticvariablesreferencedwithinaninterruptserviceroutine

Variablessharedbymultipletasksinamulti-threadedapplication

9.

Canapointerbevolatile?

Explain.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 英语

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1