资源描述:
《c语言程序设计课件(英文)c program language 之7 structure》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、StructureXueQing2009.4StructureWhatisStructureDefinitionInitializationAccessthemembersofstructureStructureandpointerStructureandfunctionStructureandarraynumber,name,score1,score2,score3,score4WhatisStructureInordertodealwiththespecialdatawhichhasseveralmemberwithdifferentdatatype,itisneedtointr
2、oducenewdatatype.Array—anorderedsetwiththesamedatatype.1090569731inta[8]23654081inta[2][4]sametypeQuestion:intno,charname[20],floats1,s2,s3,s4onestudent:strutrueWhatisStructureStructure1StructureisaadvanceddatatypeinC.2Structureisamethodforgroupingaseveralrelateddatatypetogether.3Variableswithd
3、ifferenttypescanbegroupedinastructureThesimplevariables:inta,b;a=20,b=85;-invidualArray:floatgrade[20];sametyperelatedgrade[0]grade[1]grade[2]grade[3]……WhatisStructurenumnamegrade1grade210Li90.5A11Liu80B12Wen88B….intcharfloatcharHowcanwedefinerelateddatathathavedifferenttype?struct{intnum;charn
4、ame[10];floatgrade1;chargrade2;};WhatisStructureAllvariableswiththesametypescanbegroupedinaarray.wang98889887li87668367zhan78877561liu90768172zhao87817471AllvariableswithdifferenttypescanbegroupedinastructureContentnameagesexaddwang18m3-110li20f7-121liu17f7-212zhao18m3-222structuremembers(type,
5、name)StructurevariablesDefinition132Astructureisacollectionofrelatedvariables,anynumberoftypeofvariablesmaybeincludedwithinit.Definingstructure,thendeclaringstructvariables.Definingstructureandstructvariables.structure’snamecanbeomittedkeywordstructStructuremembersSturcturevariablesStructurevar
6、iablevaluesstructname{type1member1;type2member2;︰typenmembern;};1Definingstructure,thendeclaringstructvariables.Definitionstructstudent{intnum;charname[10];floatgrade1;chargrade2;};Structureisonlyasstructuretemplate,notoccupyingmemory,becausenoanyvariableyet.A)Definingstructurenumnamegrade1grad
7、e2structdata{charname[20];intage;charaddress[30];longtelephone;}structstruct_namestruct_variable_name;structdatawang;structdatali,zhang;DefinitionB)Declaringstructurevariablenameageaddresstelephonename[20]age20bytes2bytes30bytes4b