Thread: Function Prototype, Function Call, and Function definition

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    10

    Function Prototype, Function Call, and Function definition

    I was looking all over the internet and I still havent found a simple definition of these three terms and the difference between them...I was wondering If I could get some help differing them by showing a code example with them contained.
    THANKS!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,086
    Well, surely you have some idea, even if it is not quite correct. So, what code examples would you venture to show us in answer to your question?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    10
    I have no example code and its not for Homework or anything its to study for a test. I just need an example of a Function call, Function definition, and function prototype

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,086
    As in you really don't have any idea? For example, consider this program:
    Code:
    #include <stdio.h>
    
    /* A: */
    void print_hello(void);
    
    int main(void)
    {
        /* B: */
        print_hello();
    
        return 0;
    }
    
    /* C: */
    void print_hello(void)
    {
        printf("%s\n", "Hello world!");
    }
    Match "Function call", "Function definition", and "function prototype" with the portions labelled "A", "B" and "C". If you cannot do this, re-read your learning material again and just give it your best shot with an explanation of why you think what matches with what.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    10
    Function Prototype: A
    Function Call: B
    Function Definition: C

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,086
    That wasn't so hard, was it?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Feb 2013
    Posts
    10
    Lol the problem isnt the matching, the problem is if I'm asked what is the difference between these functions? Using computer terms of course would be nice and would make me feel more intelligent in computer programming...

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,086
    Okay, at a syntactic level, think: why did you match what you matched? How do you know that they are what they are?

    Next, what happens if you don't have the prototype in the program that I posted? What happens (or does not happen) if you don't have the function call? What happens if you don't have the function definition?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Feb 2013
    Posts
    10
    To be honest, thats the order we learned that most general programs go in. I i had an idea i would say the function call in your code would be referring back to the function prototype. Without the function definition the program wouldnt know what to output I think.

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,086
    Well, okay. I suggest that you take a look at Stroustrup's C++ glossary:
    Declaration
    Definition
    function prototype
    The explanations may contain C++ specific stuff, but generally it is the same.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 01-04-2013, 03:10 AM
  2. Why put the prototype inside the function definition?
    By Overworked_PhD in forum C Programming
    Replies: 14
    Last Post: 01-11-2010, 01:48 PM
  3. Replies: 13
    Last Post: 08-24-2006, 12:22 AM
  4. Function Prototype and Definition
    By XDarklytez in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2005, 01:28 PM
  5. call to function without prototype
    By lgbeeb in forum C Programming
    Replies: 2
    Last Post: 03-25-2003, 12:20 PM