lect2_1

lect2_1 - C++ Basics - Part 1 1 C++ Basics Integer data...

Info iconThis preview shows pages 1–4. 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

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++ Basics - Part 1 1 C++ Basics Integer data types In our first program the data type of the variables we have used is int . Thus we can store whole numbers in these variables. In this part, we will discuss: two other integer types long and short for storing whole numbers. double and float types for storing numbers with a fractional or decimal part. char data type for single characters. the const data type for constants. various arithmetic operators and their rules of precedence. the bool data type for logical expressions. C++ Basics - Part 1 2 Integer data types C++ has three integer data types as indicated below. Type Bytes used Range------------------- long 4-2,147,483,648 to 2,147,483,647 short 2-32,768 to 32,767 int 2 or 4 same as long on newer compilers same as short on older compilers The largest value one can store in a variable of type long is 2,147,483,647 (= 2 31- 1). We can determine the size of a variable (number of bytes used) and what the largest and smallest int values are on our system by having a program output the value for them. For example consider the following program. #include <iostream> // for older compilers replace these #include <climits> // three lines with #include <iostream.h> using namespace std; // and #include <limits.h> int main() { cout << "Memory bytes used for integer types by my system" << endl; cout << "variable type long: " << sizeof(long) << endl; cout << "variable type short: " << sizeof(short) << endl; cout << "variable type int: " << sizeof(int) << endl; cout << "Largest and smallest integers on my system" << endl; cout << "Largest integer value = " << INT_MAX << endl; cout << "Smallest integer value = " << INT_MIN << endl; return 0; } The above program produces the following output. C++ Basics - Part 1 3 Memory bytes used for integer types by my system variable type long: 4...
View Full Document

Page1 / 7

lect2_1 - C++ Basics - Part 1 1 C++ Basics Integer data...

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