Professional Documents
Culture Documents
C++ Notes
C++ Notes
- pass by reference
_________________________________________
ariable types
int
float
double
char - single characters, such as 'a' or 'B'
string
bool
// unchangeable
const int myNum = 15
// double VS float
The precision of float is only six or seven decimal digits, while double variables
have a precision of about 15 digits. Therefore it is safer to use double for most
calculations.
// Pointers
// A pointer is a variable that stores the memory address as its value.
string food = "Pizza"; // Variable declaration
string* ptr = &food; // Pointer declaration
// Reference: Output the memory address of food with the pointer (0x6dfed4)
cout << ptr << "\n";
_________________________________________________________________________
Functions
void myFunction() {
// code to be executed
}
//void means that the function does not have a return value.
int main() {
myFunction();
return 0;
}
void myFunction() {
cout << "I just got executed!";
}
// Error
------------
You will often see C++ programs that have function declaration above main(), and
function definition below main(). This will make the code better organized and
easier to read
//Pass By Reference
// Function Overloading
Instead of defining two functions that should do the same thing, it is better to
overload one.