avatarJake Cutter

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

958

Abstract

ion(){</p><p id="c910">cout << “ I just got executed!”;</p><p id="50ca">}</p><p id="9357">int main(){</p><p id="2af3">myFunction();</p><p id="a5f2">return 0;</p><p id="16df">}</p><p id="c39b"><b>Explanation:</b></p><p id="e020">In the above program, myFunction and main are the two functions within the program. main() is where the program starts. This is the mass majority of what your attempting to execute. myFunction is the thing that is called by main() to execute myFunction.</p><p id="2861"><b>Example 2:</b></p><p id="b157">void myFunction(string fname){</p><p id="8d07">cout << fname << “Doe”;</p><p id="9aaa">}</p><p id="fe64">int main(){</p><p id="b563">myFunction(“John”);</p><p id="46df">return 0;</p><p id="c018">}</p><p id="ce4c"><b>Explanation:</b></p><p id="6f00">The outside function, myFunction, gets called by main with a given parameter, fname. Void allows your function to not require a return output in C++.</p><p id=

Options

"e1f3"><b>Example 3:</b></p><p id="e163">void myFunction(int x, int y){</p><p id="3071">int temp_var = x* 5;</p><p id="b5fe">int temp_var_2 = y / 5;</p><p id="cac4">cout << temp_var;</p><p id="3d26">cout << temp_var_2;</p><p id="645d">}</p><p id="64e9">int main(){</p><p id="f22d">myFunction(4,5);</p><p id="7ca6">return 0;</p><p id="2d5b">}</p><p id="8ce6"><b>Explanation:</b></p><p id="c9f5">The program takes the two parameters, 4 & 5, and plugs them into myFunction’s math operations.</p><p id="e1a6"><b>Note:</b></p><p id="e3d8">First two coding examples taken from <a href="https://www.w3schools.com/cpp/exercise.asp?filename=exercise_classes1">https://www.w3schools.com/cpp/exercise.asp?filename=exercise_classes1</a></p><p id="13e9">This is a great place to practice your C++ skills. It gives you answers if you can’t figure it out with 58 different practice problems. <b>Not affiliated</b>, it's just a good site.</p></article></body>

Using Functions — Computer Science

As stated in an earlier writing, a Function is a way, our computers characterize a way that a program reads information. It's like a file folder we may have in our offices. Each function is a different folder, but it may still be in the same drawer.

Photo by Christopher Gower on Unsplash

Functions are highly useful when it comes to simplifying your code down so that others can understand your work, it organizes different processes in the program, and it makes your program run better & smoother.

Example:

void myFunction(){

cout << “ I just got executed!”;

}

int main(){

myFunction();

return 0;

}

Explanation:

In the above program, myFunction and main are the two functions within the program. main() is where the program starts. This is the mass majority of what your attempting to execute. myFunction is the thing that is called by main() to execute myFunction.

Example 2:

void myFunction(string fname){

cout << fname << “Doe”;

}

int main(){

myFunction(“John”);

return 0;

}

Explanation:

The outside function, myFunction, gets called by main with a given parameter, fname. Void allows your function to not require a return output in C++.

Example 3:

void myFunction(int x, int y){

int temp_var = x* 5;

int temp_var_2 = y / 5;

cout << temp_var;

cout << temp_var_2;

}

int main(){

myFunction(4,5);

return 0;

}

Explanation:

The program takes the two parameters, 4 & 5, and plugs them into myFunction’s math operations.

Note:

First two coding examples taken from https://www.w3schools.com/cpp/exercise.asp?filename=exercise_classes1

This is a great place to practice your C++ skills. It gives you answers if you can’t figure it out with 58 different practice problems. Not affiliated, it's just a good site.

Coding
Computer Science
Functional Programming
Computers
Organization
Recommended from ReadMedium