Calling a Functions in Programming
Once a function is declared, it can be used or “called” by its name. When a function is called, the control of the program jumps to that function, which then executes its code. Once the function finishes executing, the control returns to the part of the program that called the function, and the program continues running from there.
#include <iostream>
using namespace std;
// Function Definition
void greet() { cout << "Hello, World!" << endl; }
int main()
{
// Calling the function
greet();
return 0;
}
public class HelloWorld {
// Function Definition
public static void greet()
{
System.out.println(
"Hello, World!"); // Print "Hello, World!"
}
public static void main(String[] args)
{
// Calling the function
greet(); // Call the greet function
}
}
// This code is contributed by shivamgupta0987654321
class HelloWorld:
# Function Definition
@staticmethod
def greet():
print("Hello, World!") # Print "Hello, World!"
@staticmethod
def main():
# Calling the function
HelloWorld.greet() # Call the greet function
# Execute main method
HelloWorld.main()
// Function Definition
function greet() {
console.log("Hello, World!");
}
// Calling the function
greet();
Output
Hello, World!
Functions in Programming
Functions in programming are modular units of code designed to perform specific tasks. They encapsulate a set of instructions, allowing for code reuse and organization. In this article, we will discuss about basics of function, its importance different types of functions, etc.
Table of Content
- What are Functions in Programming?
- Importance of Functions in Programming
- Functions Declaration and Definition
- Calling a Functions in Programming
- Parameters and Return Values
- Built-in Functions vs. User-Defined Functions
- Recursion in Functions
- Tips for Functions in Programming
- Conclusion
Contact Us