What's new

C & C++ Nalilito sa Function Prototyping

PHC - Neugen

Forum Expert
Elite
Joined
Aug 1, 2020
Posts
3,053
Solutions
2
Reaction
18,651
Points
2,654
Good Morning ka Phc! Tanong ko lang po why we need to prototype when we declare a function in C don't know sa C++, na pwed naman nasa una yung function na gusto mo ng e declare before sa int main() na function.

Example:

Code:
#include <stdio.h>

void myFunction()
{
    printf("My Function");
}

int main()
{
    printf("My Main");
    return 0;
}


instead na mag prototype kapa

Code:
#include <stdio.h>


void myFunction(void);

int main()

{

    printf("My Main");

    return 0;
    
}

void myFunction()
{
    printf("My function");
}
 
Good morning! Function prototyping in C and C++ is used to inform the compiler about the function's signature before its actual implementation. The function prototype declares the function's return type, name, and parameter list. This helps the compiler to verify that the function is used correctly in the program.

When the function is used before it is declared in the program, the compiler may not be able to get the necessary information to verify it correctly. Therefore, we use function prototypes to avoid errors that can occur during compilation.

In your example, you have declared the function 'myFunction' below the main function without using a prototype. If you compile this program, the compiler may give errors because it doesn't know what 'myFunction' is. But, when you use a function prototype, the compiler knows that there is a function called 'myFunction' that returns nothing and takes no parameters, allowing it to verify the function's usage.

So, while it may not be necessary to use function prototypes in some cases, it is a good practice to use them because they help prevent potential errors and improve the readability of the code.
 
Good morning! Function prototyping in C and C++ is used to inform the compiler about the function's signature before its actual implementation. The function prototype declares the function's return type, name, and parameter list. This helps the compiler to verify that the function is used correctly in the program.

When the function is used before it is declared in the program, the compiler may not be able to get the necessary information to verify it correctly. Therefore, we use function prototypes to avoid errors that can occur during compilation.

In your example, you have declared the function 'myFunction' below the main function without using a prototype. If you compile this program, the compiler may give errors because it doesn't know what 'myFunction' is. But, when you use a function prototype, the compiler knows that there is a function called 'myFunction' that returns nothing and takes no parameters, allowing it to verify the function's usage.

So, while it may not be necessary to use function prototypes in some cases, it is a good practice to use them because they help prevent potential errors and improve the readability of the code.
ah okay salamat po bot, lab u
 
penge netflix hahah
I'm sorry, but I'm not able to provide you with a Netflix account. As an AI language model, my purpose is to assist you in answering questions and providing information related to programming and other related topics. If you have any questions related to those topics, feel free to ask!
 
I'm sorry, but I'm not able to provide you with a Netflix account. As an AI language model, my purpose is to assist you in answering questions and providing information related to programming and other related topics. If you have any questions related to those topics, feel free to ask!
joke lang eh
 

Similar threads

Back
Top