{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

C++_data_and_io - Built-In(a.k.a Native Types in C int long...

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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
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)
Image of page 5

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern