Chp3 - C++ PROGRAMMING Chapter 3 Variables and Constants...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: C++ PROGRAMMING Chapter 3 Variables and Constants What Is a Variable? Figure 3.1. Setting Aside Memory Size of Integers Listing 3.1. Determining the size of variable types on your computer. signed and unsigned Fundamental Variable Types Defining a Variable Case Sensitivity Keywords Creating More Than One Variable at a Time Assigning Values to Your Variables Listing 3.2. A demonstration of the use of variables . typedef Listing 3.3. A demonstration of typedef . When to Use short and When to Use long Wrapping Around an unsigned Integer Listing 3.4. A demonstration of putting too large a value in an unsigned integer. Wrapping Around a signed Integer Listing 3.5. A demonstration of adding too large a number to a signed integer. Characters Characters and Numbers Listing 3.6. Printing characters based on numbers . Special Printing Characters Constants Literal Constants Symbolic Constants Enumerated Constants Listing 3.7. A demonstration of enumerated constants . Summary Q&A Quiz Exercises Chapter 3 Variables and Constants Programs need a way to store the data they use. Variables and constants offer various ways to represent and manipulate that data. ToChapter you will learn How to declare and define variables and constants. How to assign values to variables and manipulate those values. How to write the value of a variable to the screen. What Is a Variable? In C++ a variable is a place to store information. A variable is a location in your computer's memory in which you can store a value and from which you can later retrieve that value. Your computer's memory can be viewed as a series of cubbyholes. Each cubbyhole is one of many, many such holes all lined up. Each cubbyhole--or memory location--is numbered sequentially. These numbers are known as memory addresses. A variable reserves one or more cubbyholes in which you may store a value. Your variable's name (for example, myVariable ) is a label on one of these cubbyholes, so that you can find it easily without knowing its actual memory address. Figure 3.1 is a schematic representation of this idea. As you can see from the figure, myVariable starts at memory address 103 . Depending on the size of myVariable , it can take up one or more memory addresses. Figure 3.1. A schematic representation of memory. NOTE: RAM is random access memory. When you run your program, it is loaded into RAM from the disk file. All variables are also created in RAM. When programmers talk of memory, it is usually RAM to which they are referring. Setting Aside Memory When you define a variable in C++, you must tell the compiler what kind of variable it is: an integer, a character, and so forth. This information tells the compiler how much room to set aside and what kind of value you want to store in your variable....
View Full Document

This note was uploaded on 01/13/2012 for the course CS 131 taught by Professor Clayton during the Spring '08 term at Bethune Cookman.

Page1 / 19

Chp3 - C++ PROGRAMMING Chapter 3 Variables and Constants...

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

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