Interview question

This is a discussion on Interview question within the C Programming forums, part of the General Programming Boards category; Hi folks i faced this interview question in Bosch... they asked me to write prototype fora function that returns pointer ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    11

    Interview question

    Hi folks
    i faced this interview question in Bosch... they asked me to write prototype fora function that returns pointer to a function that returns integer

    please let me know the prototype for above question..

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    If this is an interview question, then you should probably at least put in some effort to solve it yourself. I'm not stopping anyone else from giving you the answer, but I'd suggest reading some tutorials and at least giving it a go (and posting the result if you have trouble).

    There are a couple of decent function pointer tutorials online, and they aren't really that difficult if you are familiar with both functions and pointers.

    The Function Pointer Tutorials - Index

  3. #3
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    Google "C Right-Left rule".
    Last edited by Overworked_PhD; 04-29-2010 at 10:09 AM.

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    11
    @DeadPlanet
    Thanks for the link you provided.. i hope below prototype is correct ..

    function returning pointer to a function with two int arguments that returns int

    int (*pfunc(int ))(int, int)
    Last edited by vijay s; 04-29-2010 at 01:27 PM.

  5. #5
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    602
    Not quite, can you explain why you are doing:



    (*pfunc(int)) /*what is the point of (int) here? */

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,650
    Quote Originally Posted by vijay s
    Thanks for the linl you provided.. i hope below prototype is correct ..
    Instead of hoping, check. It looks like you do not want pfunc to take any arguments, so you should actually write:
    Code:
    int (*pfunc(void))(int, int);
    Frankly, I would just reach for a typedef:
    Code:
    typedef int (*Function)(int, int);
    
    Function pfunc(void);
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    602
    That works as well, and probably preferred.

    Typedef

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c Interview question.
    By bkankur in forum C Programming
    Replies: 3
    Last Post: 12-10-2009, 06:53 AM
  2. SDL buffer channels question
    By TriKri in forum Game Programming
    Replies: 3
    Last Post: 12-09-2009, 04:52 PM
  3. Newbie question, C #
    By mate222 in forum C# Programming
    Replies: 4
    Last Post: 12-01-2009, 05:24 AM
  4. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM

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