-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.cpp
More file actions
23 lines (15 loc) · 855 Bytes
/
functions.cpp
File metadata and controls
23 lines (15 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
void speak(); // Because function is defined after main() we must declare the function and define later (or define before main())
void speakName(std::string name);
int main() {
speak(); // Call the "speak" function
speakName("Test"); // Call the "speakName" function and pass a value to the "name" argument (seperate values with commas)
return 0;
}
void speak() { // Define a function (a piece of code that can be called again and again)
std::cout << "Hello!\n";
}
void speakName(std::string name) { // Define a function but add a argument (variable) yhat can be used in the funtion (seperate arguments with commas) constants can be used in argument declareation
std::cout << name << '\n';
}
// Functions can share the same name as long as the arguments are dirrerent, these are called overloaded functions