Question about Pointer syntax in function declarations?

This is a discussion on Question about Pointer syntax in function declarations? within the C++ Programming forums, part of the General Programming Boards category; So I'm reading through "Jumping into C++" and I've made way through to chapter 15: "intro to data structures w/ ...

  1. #1
    Registered User
    Join Date
    Jul 2012
    Location
    Syracuse, New York, United States
    Posts
    2

    Question about Pointer syntax in function declarations?

    So I'm reading through "Jumping into C++" and I've made way through to chapter 15: "intro to data structures w/ linked lists". This has been the most difficult for me to wrap my head around so far. It's sort of making sense to me on a theoretical level but there is a bit of syntax that confuses me. Why do I need to use "*" when declaring a function, or rather what effect does this have?

    Code:
    //exp function deceleration
    
    type* funcName ();
    
    //type = a structure if that's relevant


    The only information I've been able to gather via google involves pointers to function but that is a different topic and a different syntax...

    This is probably going to sound silly to most of you more experienced programmers but I'm still learning and I'm finding it difficult to find information about this particular syntax.

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    No, this isn't a function pointer.
    This is a function that returns a pointer.

    (If you write one, remember not to return a local address.)
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,629
    It's a function whose return type is type*.
    Eg:
    int* foo();
    A function named foo that returns an int* (pointer to an int).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Jul 2012
    Location
    Syracuse, New York, United States
    Posts
    2
    Thanks manasij7479 and Elysia, I had suspected that was what was going on but I couldn't find any hard evidence to confirm it, very helpful, makes perfect sense.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 01-04-2012, 12:25 AM
  2. Problem with a function pointer syntax
    By manasij7479 in forum C++ Programming
    Replies: 15
    Last Post: 07-04-2011, 11:08 AM
  3. Replies: 2
    Last Post: 12-01-2010, 12:05 PM
  4. Function syntax to return a pointer...
    By tzuch in forum C Programming
    Replies: 1
    Last Post: 05-29-2008, 07:53 AM
  5. struct pointer to function syntax
    By kermit in forum C Programming
    Replies: 2
    Last Post: 03-21-2004, 03:01 PM

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