Using the pointer * in the function header

Thread Starter

asilvester635

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

Code:
int* function() {
    // code...
} // end of function
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().
 

WBahn

Joined Mar 31, 2012
30,060
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.
 

Thread Starter

asilvester635

Joined Jan 26, 2017
73
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.
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.
 

WBahn

Joined Mar 31, 2012
30,060
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. I'm sorry for bombarding this forum with my basic questions.
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.
 

Papabravo

Joined Feb 24, 2006
21,225
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.
 
Top