资源描述:
《国外c语言程序设计英文课件-lectu》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、ComputerProgrammingLecture202.10.2012Lecture2:OutlineVariables,DataTypes,andArithmeticExpressions[K-ch.4]WorkingwithVariablesUnderstandingDataTypesandConstantsTheBasicIntegerTypeintTheFloatingNumberTypefloatTheExtendedPrecisionTypedoubleTheSingleCharacterTypecharTheBool
2、eanDataType_BoolStoragesizesandrangesTypeSpecifiers:long,longlong,short,unsigned,andsignedWorkingwithArithmeticExpressionsIntegerArithmeticandtheUnaryMinusOperatorTheModulusOperatorIntegerandFloating-PointConversionsCombiningOperationswithAssignment:TheAssignmentOperato
3、rsTypes_Complexand_ImaginaryVariablesProgramscanusesymbolicnamesforstoringcomputationdataVariable:asymbolicnameforamemorylocationprogrammerdoesn’thavetoworryaboutspecifying(orevenknowing)thevalueofthelocation’saddressInC,variableshavetobedeclaredbeforetheyareusedVariabl
4、edeclaration:[symbolicname(identifier),type]DeclarationsthatreservestoragearecalleddefinitionsThedefinitionreservesmemoryspaceforthevariable,butdoesn’tputanyvaluethereValuesgetintothememorylocationofthevariablebyinitializationorassignementVariables-Examplesinta;//declar
5、ingavariableoftypeintintsum,a1,a2;//declaring3variablesintx=7;//declaringandinitializingavariablea=5;//assigningtovariableathevalue5a1=a;//assigningtovariablea1thevalueofaL-valueR-valuea1=a1+1;//assigningtovariablea1thevalueofa1+1//(increasingvalueofa1with1)Variabledecl
6、arationsDatatypeVariablenameWhichdatatypesarepossibleinC?WhichvariablenamesareallowedinC?VariablenamesRulesforvalidvariablenames(identifiers)inC:Namemustbeginwithaletterorunderscore(_)andcanbefollowedbyanycombinationofletters,underscores,ordigits.Anynamethathasspecialsi
7、gnificancetotheCcompiler(reservedwords)cannotbeusedasavariablename.Examplesofvalidvariablenames:Sum,pieceFlag,I,J5x7,Number_of_moves,_sysflagExamplesofinvalidvariablenames:sum$value,3Spencer,int.Ciscase-sensitive:sum,Sum,andSUMeachrefertoadifferentvariable!Variablenames
8、canbeaslongasyouwant,althoughonlythefirst63(or31)charactersmightbesignificant.(Anyway,it’snotpracticaltousevar