1. integer division truncates: any fractional part is discarded.
(int): 5/9 = 0
2. printf (a standard function can be called by C, ANSI standard)
\t, tab; \n, new line
%d print as decimal integer,
%6d a least 6 characters wide
%f floating point
%6f 6 characters wide
%.2f 2 characters after decimal point
%6.2f at least 6 wide, 2 after decimal point
Memory
A variable in C++ is a name for a piece of memory that can be used to store information. When a variable is declared, a piece of that memory is set aside for that variable.
First, there is no guarantee that your variables will be assigned the same memory address each time your program is run. The first time you run your program, x may be assigned to memory location 140. The second time, it may be assigned to memory location 168. Second, when a variable is assigned to a memory location, the value in that memory location is undefined (in other words, whatever value was there last is still there). A variable that has not been assigned a value is called an uninitialized variable. Uninitialized variables are very dangerous because they cause intermittent problems (due to having different values each time you run the program).
A good rule is to always assign values to variables when they are declared.
Function
Typically, when learning C++, you will write a lot of programs that involve 3 subtasks:
- Reading inputs from the user
- Calculating a value from the inputs
- Printing the calculated value
Compile
When addressing compile errors in your programs, always resolve the first error produced first.
No comments:
Post a Comment