Function

Function that generate a pointer type like node<itemtype>*getNext() what is this actually ?i having confusion
i having confusion


You seem to be always "having confusion". Is it that, or are you still trolling?

Consider getting a good text book and reading it. Start from the basics.
It's just what it says: a function that returns a pointer.

When you write a function that returns a pointer, you need to be very clear with yourself and code that calls the function about a few things:
- Can the pointer be null?
- How long is the pointed-at data valid?
- Does the pointer need to be deleted by the caller?

Also, try to avoid this common mistake:

1
2
3
4
5
6
Data *findData(args) {
    get the data
    if (error occurred) return nullptr;
    else if (no data found) return nullptr;
    else return foundData;
}

The problem here is that the caller has no way to distinguish between "an error occurred" and "there is no data to return."

i also can set parameter as pointer and return pointer right?
Yes.
Topic archived. No new replies allowed.