Using the pointer * in the function header

Discussion in 'Programmer's Corner' started by asilvester635, Feb 11, 2017.

  1. asilvester635

    Thread Starter Member

    Jan 26, 2017
    67
    2
    I was curious what it means when you have the code below. Why would this be useful?

    Code (Text):
    1.  
    2. int* function() {
    3.     // code...
    4. } // end of function
    5.  
    int* x = a
    The code right above declares a pointer to an int. This is used to store the pointer of a inside x. Though I'm a little unsure why we would use * in the function header such as int* function().
     
  2. AlbertHall

    Distinguished Member

    Jun 4, 2014
    3,044
    650
  3. WBahn

    Moderator

    Mar 31, 2012
    18,833
    5,122
    You keep asking basic questions like you've never had any exposure to this stuff at all. That will hold the rate at which you learn this stuff to a snail's pace because you have to deal with the turn around time of waiting for people to respond and possibly needing to engage in a two- (or multi- way discussion to get at what you are asking. You REALLY need to invest in a text book and read it. Then you can immediately explore the information you are trying to discover and let your curiosity guide you quest. Every C/C++ text I have ever seen has an extensive section on pointers including examples of passing pointers to functions and functions returning pointers. Most also include passing and returning pointers to functions.
     
  4. asilvester635

    Thread Starter Member

    Jan 26, 2017
    67
    2
    Sorry, my class don't have a textbook. Well, we do, it's the professors textbook (not professionally published). He writes and updates it as the class progresses. So not everything is in there. I do watch youtube videos, which help, but youtube doesn't cover everything.
     
  5. MrChips

    Moderator

    Oct 2, 2009
    13,153
    3,696
  6. WBahn

    Moderator

    Mar 31, 2012
    18,833
    5,122
    The issue isn't so much bombarding us with basic questions -- it's that I'm concerned that this approach is hampering the speed at which you can interact with and learn the material.

    You are not limited to the textbook your professor is writing; you CAN get others. There are several textbooks available online and you can always purchase one from any number of places. A good book for the kind of questions you are asking is, "The C/C++ Programmer's Bible". There are LOTS of used copies out there available for a few cents (plus shipping). If you live where getting physical texts is an issue, then you can purchase an electronic version (of those texts that have e-versions, of course). This topic has been around so long that there are going to be many low-cost e-texts available. You also have an unbelievable number of online tutorial sites, such as tutotialspoint.com.
     
  7. Papabravo

    Expert

    Feb 24, 2006
    10,620
    1,962
    The bonus for you is finding the answers and suggesting corrections or improvements to the professor's text. Some will appreciate your industry -- others may not. Be sure to tread carefully.
     
Loading...