
Function Declaration in C
In C, a function declaration (also called a function prototype) tells the compiler about a function's name, return type, and parameters � before it's actually defined or used. It�s like a forward declaration that enables you to call functions before they�re defined. ??
? Syntax of Function Declaration
return_type (parameter_list);
Example:
int add(int a, #include // Function declarationint add(int, () { int sum = add(5, 3); // function call printf("Sum = %d\n", sum); return 0;}// Function definitionint add(int a,
Aspect | Declaration | Definition |
---|---|---|
Purpose | Tells the compiler the function's signature | Provides the actual code |
Ends with | Semicolon (; ) | Function body {} |
Memory used? | ? No | ? Yes |
? Example Without Declaration (Leads to Error)
#include int main() { int result = multiply(2, 3); // ? Error if multiply isn't declared return 0;}int multiply(int a, int b) { return a * b;}
? Fix: Add
int multiply(int, int);
before main()
.
Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.