lecture 2
lecture 2
Introduction
Variables and assignment
• variable are used to name and store data.
• value is any type of data held by the variable.
• Variables are implemented as Memory locations assigned by the compiler
• The value of the variable Is kept in the memory location assigned to that variable.
Identifiers
• Identifier : name of the variable
• An identifier must start with a letter or an underscore
• Other characters can be letters, digits or the underscore symbol
• C++ is a case-sensitive language;
• eg Rate | RATE | rate => are different variables
Rules for writing an identifier
• Declaring a variable is telling the complier the kind of data to be stored in the
variable.
• For example:
int number_of_bars; => integer type
• When there is more than one declarations they are separated by comma.
• This assignment statement sets the value of total_weight to the value of one_weight multiplied by the
value of number_of_bars.
Using namespace std; - iostream library includes the definition of cin and cout and others
• This statement says that your program is using the std (standard) namespace.
Escape sequences
• The \ preceding a character tells the compiler that the character
following the \ doesn’t have the same meaning as the character itself.
• At variable declaration in C++, the compiler allocates memory based on the variable’s data-type
• Every data type requires a different amount of memory.
Data type
• Primitive Data Types:
• Character:
• Keyword used for character data type is char
• Characters typically requires 1 byte of memory space
• ranges from -128 to 127 or 0 to 255
• Boolean:
• used for storing boolean or logical values (true or false)
• Keyword used for boolean data type is bool
Primitive Data type …
• Floating Point:
• used for storing single precision floating point values or decimal values
• Valueless or Void:
• Void means without any value.
• Void data type is used for those function which does not returns a value.
Data type Modifiers
Operators
• An operator is a symbol that tells the compiler to perform specific
mathematical or logical manipulations.
• Arithmetic Operators
• Assignment Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Misc Operators
Operators …
Arithmetic Operators
Operators …
Assignment Operators
Operators …
Assignment Operators …
Operators …
Relational Operators
Operators …
Logical Operators
Operators …
Bitwise Operators
Operators …
Postfix vs Prefix