The Basic Data Types
- Basic data types
- char - character
8 bit ASCII characters
- wchar_t - wide character
for languages with large number of characters
- int - integer
no fractional component
- float - floating point
has fractional component
- double - double floating point
about 10 x larger than float
- bool - Boolean
true or false
- void - valueless
when a value isn't returned
- Declaration of variables
- type variable_list;
- where declared
- local variables - inside functions
- created when the function is called
- destroyed when the function is exited
- formal parameters - in the definition of function parameters
- arguments of a function
- like a local variable
- global variables - outside of all functions
- declare them outside all functions - at the top
of the program
- Type Modifiers
- signed
applied to integers (redundant) and characters
- unsigned
applied to integers and characters
- long
applied to double
- short
applied to integers
- Constants
- Fixed values that cannot be altered by the program
- Types
- character constants are between single quotes ` `
- wide character - precede the character with L
- integers - numbers without fractional component
- floating-point - decimal point or scientific notation
- type can be specified
- hexadecimal - 0x
- octal - begins with 0
- strings - an array of characters - double quotes " "
- Blackslash character constants
- \b - backspace
- \f - form feed
- \n - newline
- \r - carriage return
- \t - horizontal tab
- \" - double quotes
- \' - single quote
- \\ - backslash
- \v - vertical tab
- \a - alert
- \? - ?
- \N - octal constant
- \xN - hexadecimal constant
- Variable Initialization
- type variable_name = constant;
- global variables initialized only at the start of a program
- local variables initialized each time the function is entered
unknown value until an assignment is made unless specified
- Operators - a symbol that tells the compiler to perform specific mathematical or logical manipulations
- arithmetic operators -
- standard + - * /
- modulus % - remainder of an integer division
- can't be used with float or double
- increment and decrement
- increment ++ adds one
- decrement -- subtracts one
- relational - > ,>=,<,<+,==,!=
- outcome is a bool
- logical
- AND - &&
- OR - ||
- NOT - !
- precedence of operators
- Expressions
- when different types are used in expressions, they are converted to the same type
- convert up to lartest operand
- casts - force an expression to be a specific type (type) expression
- spacing and parentheses
are use for clarification
Back to the Main Menu