1. C++ basics - ENGG1002 Computer Programming and...

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

View Full Document Right Arrow Icon
ENGG1002 Computer Programming and Applications Prepared by Dr. K.K.Y. Wong
Image of page 1

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

View Full Document Right Arrow Icon
Variables Variables in computer programming Used to store data Implemented as memory locations The compiler will assign an appropriate number of memory cells in the main memory to each variable according to the type of data to be stored Referred to by its identifier (the name of a variable) The data stored in a variable may change over time 2 int main() { int width = 5; int height = 10; int area = width * height; return area; } variables
Image of page 2
Identifier An identifier must start with either a letter (i.e., A to Z , and a to z ), or the underscore symbol (i.e., _ ) The rest of the character may be letters (i.e., A to Z , and a to z ), digits (i.e., 0 to 9 ), or the underscore symbol (i.e., _ ) C++ is case-sensitive So radius , RADIUS , Radius , etc., are different Cannot be a keyword in C++ 3
Image of page 3

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

View Full Document Right Arrow Icon
Keywords in C++ Reserved words in C++ with predefined meanings Cannot be used as names for variables or anything else C++ Keywords: 4 asm auto bool break case catch char class const const_cast continue default delete do double dynamic_cast else enum explicit extern false float for friend goto if inline int log long mutable namespace new operator private protected public register reinterpret_cast return short signed sizeof static static_cast struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while
Image of page 4