Unformatted text preview: , can assign a value at declaration
x Examples: int foo;
iint bar = 42;
4 Basic types in C++
x How to determine the data type for a variable?
x Simple: look for the basic type in C++, and find a match
x Basic types: iint: a number which is an integer
nt: • ex: 12345, 0, -42 float: an arbitrary number (integer or floating point)
• ex: -1.33, -42.0, 42.0, 0.0
ex: char: a single character • ex: ‘a’, ‘b’
ex: 5 iint: examples
int x = 42; // ok
int x = 0; // ok
int x = 421234234535; // error (out of range)
int x = -1; // ok
unsigned x = -1; // error (-1 is signed)
int x = -42; // ok
int x = 42.12; // not ok (not integer)
6 Be careful!
x What are semantics errors may not be reported as errors
What by the compiler!
x Reason: the C++ standard defines what to do for those
cases Example: unsigned int x = -1 is defined, will hold maxint!
x Be extra cautious: it is the duty of the programmer to
Be determine the range of variables
View Full Document
This note was uploaded on 04/03/2014 for the course CS 31 taught by Professor Melkanoff during the Fall '00 term at UCLA.
- Fall '00