资源描述:
《国外C语言程序设计英文课件-lecture2.ppt》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、ComputerProgrammingLecture202.10.2012Lecture2:OutlineVariables,DataTypes,andArithmeticExpressions[K-ch.4]WorkingwithVariablesUnderstandingDataTypesandConstantsTheBasicIntegerTypeintTheFloatingNumberTypefloatTheExtendedPrecisionTypedoubleTheSingleCharacterTypecharTheBooleanDataType_
2、BoolStoragesizesandrangesTypeSpecifiers:long,longlong,short,unsigned,andsignedWorkingwithArithmeticExpressionsIntegerArithmeticandtheUnaryMinusOperatorTheModulusOperatorIntegerandFloating-PointConversionsCombiningOperationswithAssignment:TheAssignmentOperatorsTypes_Complexand_Imagi
3、naryVariablesProgramscanusesymbolicnamesforstoringcomputationdataVariable:asymbolicnameforamemorylocationprogrammerdoesn’thavetoworryaboutspecifying(orevenknowing)thevalueofthelocation’saddressInC,variableshavetobedeclaredbeforetheyareusedVariabledeclaration:[symbolicname(identifie
4、r),type]DeclarationsthatreservestoragearecalleddefinitionsThedefinitionreservesmemoryspaceforthevariable,butdoesn’tputanyvaluethereValuesgetintothememorylocationofthevariablebyinitializationorassignementVariables-Examplesinta;//declaringavariableoftypeintintsum,a1,a2;//declaring3va
5、riablesintx=7;//declaringandinitializingavariablea=5;//assigningtovariableathevalue5a1=a;//assigningtovariablea1thevalueofaL-valueR-valuea1=a1+1;//assigningtovariablea1thevalueofa1+1//(increasingvalueofa1with1)VariabledeclarationsDatatypeVariablenameWhichdatatypesarepossibleinC?Whi
6、chvariablenamesareallowedinC?VariablenamesRulesforvalidvariablenames(identifiers)inC:Namemustbeginwithaletterorunderscore(_)andcanbefollowedbyanycombinationofletters,underscores,ordigits.AnynamethathasspecialsignificancetotheCcompiler(reservedwords)cannotbeusedasavariablename.Examp
7、lesofvalidvariablenames:Sum,pieceFlag,I,J5x7,Number_of_moves,_sysflagExamplesofinvalidvariablenames:sum$value,3Spencer,int.Ciscase-sensitive:sum,Sum,andSUMeachrefertoadifferentvariable!Variablenamescanbeaslongasyouwant,althoughonlythefirst63(or31)charactersmightbesignificant.(Anywa
8、y,it’snotpracticaltousevar