I have answer correct?

This is a discussion on I have answer correct? within the C Programming forums, part of the General Programming Boards category; What do the following statements? Code: int f1(int a, double (*f)(float *b)); f1 is a function that returns an integer ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    71

    I have answer correct?

    What do the following statements?


    Code:
    int f1(int a, double (*f)(float *b));
    f1 is a function that returns an integer and has two parameters:first is a int and the second is an pointer to a function than returns an double and than has a parameter:a pointer to a float.

    Code:
    int f2(int a, double f(char c), int (*g)(int d, int *e));
    f2 is function than returns an integer and has three parametrers:a integer,a function f than returns a double and has a parameter(a char), a pointer to a function than returns a int and has two parameters:a int and a pointer to int.

    Code:
    float *f3(double *a, int * (*f)(double));
    f3 is a function than return a pointer to a float and has two parameters: a pointers to a double,a pointer to a function than returns a pointer to a int whith a parameter(a double)

    Code:
    double (*fc)(int a, float ff(void));
    fc is a pointer to a function than returns a double and has two parameters:an int,a function than returns a float and has non parameters.

    Code:
    int *(*fd)(float *a, double *f(int *d));
    fd is a pointer to a function than returns a pointer to a int and has two parameters:a pointer to a int,a function than returns a pointer to a double and has a pointer to a int
    Last edited by nutzu2010; 02-26-2011 at 08:03 AM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Just looked at f1, and the error is that the function f parameter is a pointer to float, not a pointer to double.

    You've got the right idea, however.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    71
    first time I've written on a sheet, After that I wrote on the computer...Maybe that's why I wrote wrong

    I want to learn pointer to functions
    If these answers are correct you can I still put a few questions?
    Last edited by nutzu2010; 02-26-2011 at 08:08 AM.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    f2 looked good, watch your spelling of parameters though. (doesn't bother me, but it might bother your boss or instructor).

    Sure, if it's on this topic, ask away!

    If it's on a different topic, please start up a new thread so it gets the attention it deserves.

  5. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    71
    ok,f2 is correct,but f3,fd,fc ?

    Sure, if it's on this topic, ask away!
    no,i wanna - you ask me any questions about "pointer to functions"(outside structures)

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    What's wrong with this one?
    Code:

    Code:
    int *(*fd)(float *a, double *f(int *d));
    fd is a pointer to a function than returns a pointer to a int and has two parameters:a pointer to a int,a function than returns a pointer to a double and has a pointer to a int

  7. #7
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    cdecl
    Can be helpful tools. Of course, it's still important to understand... the concept.
    The only thing you need to take note is
    Code:
      void foo( double f(double) );
      is the same as
      void foo( double (*f)(double)) ;
    Last edited by Bayint Naung; 02-26-2011 at 08:31 AM.

  8. #8
    Registered User
    Join Date
    Dec 2010
    Posts
    71
    fd is a pointer to a function than returns a pointer to a int and has two parameters:a pointer to a float,a function than returns a pointer to a double and has a pointer to a int
    now is correct?

  9. #9
    Registered User
    Join Date
    Dec 2010
    Posts
    71
    Quote Originally Posted by Bayint Naung View Post
    cdecl
    Can be helpful tools. Of course, it's still important to understand... the concept.
    The only thing you need to take note is
    Code:
      void foo( double f(double) );
      is the same as
      void foo( double (*f)(double)) ;
    sow
    double f(double)
    is a pointer to function?

    cdecl is only for linux?

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by nutzu2010 View Post
    now is correct?
    Yes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux for GNU/Linux is not correct?
    By password636 in forum Linux Programming
    Replies: 8
    Last Post: 03-31-2009, 09:30 PM
  2. Keep getting negative sign after answer
    By uptown11 in forum C++ Programming
    Replies: 7
    Last Post: 02-23-2009, 11:14 PM
  3. how would you answer this question?
    By smoking81 in forum Linux Programming
    Replies: 3
    Last Post: 09-08-2008, 04:53 AM
  4. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 10:42 AM
  5. getting weird answer when not using ".h"
    By CobraCC in forum C++ Programming
    Replies: 10
    Last Post: 05-07-2003, 07:21 AM

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