🔒 Closed Nalilito sa Function Prototyping

Status
Not open for further replies.
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
 
Status
Not open for further replies.

About this Thread

  • 7
    Replies
  • 456
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,088
Guests online
954
Total visitors
2,042

Forum statistics

Threads
2,273,784
Posts
28,951,584
Members
1,234,954
Latest member
zreckorbion
Back
Top