Lec2 - Lecture 2: Variables and I/O PIC 10A Todd Wittman...

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

View Full Document Right Arrow Icon
1 Lecture 2: Variables and I/O PIC 10A Todd Wittman Typing Up Your Program • Thursday in the PIC Lab, I hope you noticed a couple things about typing programs. 1. C++ let’s you put spaces and returns wherever you want. cout<<“Hel”<<“lo”; cout << “Hel” << “lo”; 2. If you want a space or return to appear in the output, you have to put it there with “ “ or “\n”. cout << 2 << 3; cout << 2 << “ “ << 3; 3. The last line return 0; wasn’t necessary. But it’s good style to have it. int main( ) { cout << “hello”; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Sec 2.1 : • A variable is a storage space for a “value”, which could be a number, string (word), or even a list of numbers. • Today we’ll look at number data types. • The code x = 2; cout << “The value of x is “ << x; will output: The value of x is 2 • The first line assigns the value 2 to x. • Referring to x will look up the value 2. Numbers and Memory • Everything is 1’s and 0’s to a computer. • Numbers are represented in binary as strings of 1’s and 0’s, called bits. 2 = 00000010 131 = 01000011 • We can also represent decimals. • The “longer” the number, the more bits it takes to represent. • So number 0.0001 takes more bits to store than the number 2. 8 bits = 1 byte 1,000 bytes = 1 kilobyte 1,000,000 bytes = 1 megabyte
Background image of page 2
3 Data Types • To save memory we want to use as few bits as possible to represent our number. 80 very long float long double 64 long float double 32 floating point (e.g. 3.14) float 32 integer (e.g. 2, 0, -42) int 16 short integer short 8 Character (letter, e.g. ‘T’)
Background image of page 3

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

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

Page1 / 10

Lec2 - Lecture 2: Variables and I/O PIC 10A Todd Wittman...

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

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