functions passing parameters

This is a discussion on functions passing parameters within the C Programming forums, part of the General Programming Boards category; How do you write a function prototype for a function called protoFunc, which is passed two integer parameters and returns ...

  1. #1
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357

    functions passing parameters

    How do you write a function prototype for a function called protoFunc, which is passed two integer parameters and returns nothing using the C language?

    Also, how do you write a function prototype for a function called thatFunc, which is passed two float address pointers and returns a float?

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    1)
    void protoFunc( int, int );

    2)
    float thatFunc( float *, float * );

    Hopefully by just seeing these examples you can understand what is going on in them. Its pretty self explanatory I think. If you have specific questions just ask.

    EDIT:

    Sorry Salem

  3. #3
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807

    We don't make your homework.

    You need to understand how function prototypes works.
    Code:
    type_of_value_returned [...] name_of_function [...] (parameters [...])
    It's not so difficult, and now if we wan't to make a function called test() that receives two integers as parameters and return an int.

    [code]
    int test(int num1, int num2);
    [code]

  4. #4
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    for the float:

    If the identifier that will receive the returned float is called retFloat, then how would you write the statement that would be used to call thatFunc from within the main?

  5. #5
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    Why?

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    66
    Because you're taking without giving anything back. We want to know that you're trying, otherwise it's a waste of time helping you out and we have better things to do.

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by volk
    Why?
    In addition to what's already posted: Read the forum guidelines. Your question may or may not be homework to you, but it sure gives a strong impression of being so.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    Well, I'm trying to make a function that will figure out if a number is even or odd.

    I'm also trying to make a function that will draw a parabola based on user input.

    I'm sorry if my questions sound like homework, but c'mon, I'm just a beginner. Show a little mercy here, ok?

    Don't you guys remember when you were beginners? Huh, do you? Well...do you?

  9. #9
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807

    Look...

    Well, I'm trying to make a function that will figure out if a number is even or odd.
    so let's think together, your function should receive 1(or more, if you want) parameter and the same function should return (or not) an value, like, if the number is even, it returns 1 else returns 0.

    We did tell you how to make this, I did write above how function prototypes work.
    Code:
    type_of_value_returned [...] name_of_function [...] (parameters [...])


    I'm sorry if my questions sound like homework, but c'mon, I'm just a beginner. Show a little mercy here, ok?
    We know that you're a beginner, but if we do all your exercises you'll never learn how to do it by yourself.

    Don't you guys remember when you were beginners? Huh, do you? Well...do you?
    Every one remember, but I think at least, I tried to make my exercises, and if I did not understand something, I did try to read the book again and again.

  10. #10
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Originally posted by volk
    Well, I'm trying to make a function that will figure out if a number is even or odd.
    You're serious?... for what's it worth and not caring about 0.

    Code:
    #include <stdio.h>
    
    void oddEven(int);
    
    int main(void)
    {
       int i;
       
       for(i=0; i < 21; i++)
       	oddEven(i);
       	   
       return 0;
    }
    
    void oddEven(int number)
    {
    	if((number % 2) == 0)
    		printf("%d is Even\n", number);
    	else
    		printf("%d is Odd\n", number);
    }
    I'm also trying to make a function that will draw a parabola based on user input.
    Interesting....

    I'm sorry if my questions sound like homework, but c'mon, I'm just a beginner. Show a little mercy here, ok?
    No worries.... I'm a newb myself...

    Don't you guys remember when you were beginners? Huh, do you? Well...do you?
    How can I forget?
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb Question on Passing Objects as Parameters
    By Mariano L Gappa in forum C++ Programming
    Replies: 12
    Last Post: 11-29-2006, 12:08 PM
  2. Passing parameters between templated functions
    By SpaceCadet in forum C++ Programming
    Replies: 1
    Last Post: 11-20-2006, 02:57 PM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  4. passing structures to functions
    By AmazingRando in forum C++ Programming
    Replies: 5
    Last Post: 09-05-2003, 11:22 AM
  5. Replies: 1
    Last Post: 01-20-2002, 10:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21