C_data_and_io - Built-In(a.k.a Native Types in C int long short char(signed integer division unsigned versions too unsigned int unsigned long etc C

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

View Full Document Right Arrow Icon
CSE 332: C++ data types, input, and output Built-In (a.k.a. Native) Types in C++ int, long, short, char (signed, integer division) unsigned versions too unsigned int , unsigned long , etc. C++ guarantees a char is one byte in size Sizes of other types are platform dependent Can determine using sizeof() , <climits> INT_MAX float, double (floating point division) More expensive in space and time Useful when you need to describe continuous quantities bool type Logic type, takes on values true , false
Background image of page 1

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

View Full DocumentRight Arrow Icon
CSE 332: C++ data types, input, and output User (& Library) DefinedTypes in C++ enumerations enum primary_color {red, blue, yellow}; functions and operators For example, things called from main function structs and classes Similar abstractions in C++, extend C structs
Background image of page 2
CSE 332: C++ data types, input, and output Comparing C++ Classes and Structs struct My_Data { My_Data (int i) : x_(i) {} int x_; }; class My_Object { public: My_Object (); ~My_Object (); private: int y_; }; Struct members are public by default Class members are private by default Both can have Constructors Destructors Member variables Member functions Common practice: use structs for data use classes for objects with non-trivial methods
Background image of page 3

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

View Full DocumentRight Arrow Icon
CSE 332: C++ data types, input, and output More About Both Native and User Types Pointers raw memory address of an object or variable its type constrains what types it can point to (more later) can take on a value of 0 (not pointing to anything) References “alias” for an object or variable its type constrains what types it can refer to (more later) cannot be 0 ( always references something else) Mutable (default) vs. const types (read right to left) const int i; // read-only declaration int j; // readable and writable declaration
Background image of page 4
CSE 332: C++ data types, input, and output Scopes in C++ Each symbol is associated with a scope The entire program (global scope) A namespace (namespace scope) Members of a class (class scope) A function (function scope) A block (block scope) A symbol is only visible within its scope Helps hide unneeded details (abstraction) Helps prevent symbol conflicts (encapsulation)
Background image of page 5

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

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

This note was uploaded on 03/03/2010 for the course CSE 332S taught by Professor Smart during the Spring '08 term at Washington University in St. Louis.

Page1 / 17

C_data_and_io - Built-In(a.k.a Native Types in C int long short char(signed integer division unsigned versions too unsigned int unsigned long etc C

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

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