CP1_3_DataTypes_1112

CP1_3_DataTypes_1112 - Data Types and Data yp Expressions...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Data Types and Expressions
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Recall from previous class Main memory provides temporary storage for data and for the program being executed. byte location 00000000 byte 1000 00110101 4 byte location with address 1000 byte 1001 10001110 byte 1002 01111101 yte 1003 0000111 2 byte location with address 1004 byte 1003 00000111 byte 1004 01101010 byte 1005 01000011 4 byte location with address byte 1006 00001101 byte 1007 11100111 1006 byte 1008 11000001 byte 1009 01100110 byte 1010 0000000 2 CSIS1117B Computer Programming 1 2011-2012 y 00000000 byte 1011 00000000
Background image of page 2
Variables In programs, we define variables to store data and provide a name to access it. This allows us to store particular values, and to use those values later in the program. Every C++ variable has three attributes of interest to us: Name Type Value In reality there is another attribute: an address. A variable orresponds to some location(s) in main memory corresponds to some location(s) in main memory. But in general programming we don’t need to know the 3 CSIS1117B Computer Programming 1 2011-2012 actual address in memory that contains the variable’s value, we just use the variable’s name for that purpose.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Identifiers Identifiers are used as names for variables and other ems defined in a program. An identifier is a series of items defined in a program. An identifier is a series of characters and, to be valid, the combination of characters must obey a number of rules. A valid identifier: must start with a letter or an underscore, and the remaining characters must be letters, digits, or underscores. C++ is case-sensitive, so salary, SALARY, Salary , etc. are different. We usually use all lower-case for variables. Keywords of C++ cannot be used as variable names 4 CSIS1117B Computer Programming 1 2011-2012
Background image of page 4
Keywords in C++ Keywords are identifiers which have a pre-defined eaning in C++ They are reserved as part of the C++ meaning in C++. language and cannot be used by programmers to name variables. There are 73 keywords and 11 reserved alternate epresentations in the latest C + tandard representations in the latest C++ standard. e.g. int, return, if, else, false, double, for, and, not … All 84 reserved words are listed in the last two slides of this slide set. 5 CSIS1117B Computer Programming 1 2011-2012
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Other names to avoid Some identifiers from the standard library, such as cout , are used by programmers in a well-understood, standard way, but they are not reserved words of the C++ language. Their meaning is defined in the standard library rather than the core language. You could redefine their meaning in your own programs. But that would be a bad idea and very onfusing for anyone who needs to understand your confusing for anyone who needs to understand your code. 6 CSIS1117B Computer Programming 1 2011-2012
Background image of page 6
Which are valid C++ variable names 01154321 rogram cpp a_student 201154321 __oOOo__ program.cpp year1-student const Discount_20% an integer std Days_of_Week string main cout false ____ As on previous slide, avoid using standard names with well-known meanings as variable names, even though they are not reserved ords. words.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/15/2011 for the course CSIS 1117B taught by Professor Noneedtoknow during the Winter '11 term at HKU.

Page1 / 31

CP1_3_DataTypes_1112 - Data Types and Data yp Expressions...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online