{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

L03vars - C Basics Variables Identifiers Assignments...

Info icon This preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ Basics Variables, Identifiers, Assignments, Input/Output
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
Program Organization C++ program Collection of definitions, declarations and functions Collection can span multiple files Advantages Structured into small understandable units Complexity is reduced Overall program size decreases
Image of page 2
Variables variable can hold a number or a data of other types, it always holds something. A variable has a name the data held in variable is called value variables are implemented as memory locations and assigned certain memory address. The exact address depends on computer and compiler. we think as though the memory locations are actually labeled with variable names 12.5 32 'c' y Temperature Letter 1001 1002 1003 1004 1005 1006 1007 - Number 1008 1009
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
Identifiers name of a variable (or any other item you define in program) is called identifier identifier must start with a letter or underscore symbol ( _ ), the rest of the characters should be letters, digits or underscores the following are valid identifiers: x x1 x_1 _abc sum RateAveragE the following are not legal identifiers. Why? 13 3X %change data-1 my.identifier a(3) C++ is case sensitive: MyVar and myvar are different identifiers
Image of page 4
What Are Good Identifiers? careful selection of identifiers makes your program clearer identifiers should be short enough to be reasonable to type (single word is norm) Standard abbreviations are fine (but only standard abbreviations) long enough to be understandable two styles of identifiers C-style - terse, use abbreviations and underscores to separate the words, never use capital letters for variables Pascal-style - if multiple words: capitalize, don’t use underscores Camel Case – variant of Pascal-style with first letter lowercased pick style and use consistently ex: Pascal-style C-style Camel Case Min min min Temperature temperature temperature CameraAngle camera_angle cameraAngle CurrentNumberPoints cur_point_nmbr currentNumberPoints
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
Keywords keywords are identifiers reserved as part of the language int, return, float, double they cannot be used by the programmer to name things they consist of lowercase letters only they have special meaning to the compiler
Image of page 6
Keywords (cont.) asm do if return typedef auto double inline short typeid bool dynamic_cast int signed typename break delete long sizeof union case else mutable static unsigned catch enum namespace static_cast using char explicit new struct virtual
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
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