Has the following code any practical utility apart from showing the working of pointers?
I got it while learning c in which the tutorial showings the features of pointer.
Does a C programmer use this kind of code where a int pointer has been declared first and assigned a value inside a function?
Regards..

void check(int**);
int main()
{
    int *j;
    check(&j);
}
void check(int **i){
    int a = 20;
    *i = &a;
    }

Recommended Answers

All 4 Replies

Only if he/she likes a pointer that refers to invalid memory(int 'a' becomes invalid when the function 'check' returns).

commented: Right +0

Has the following code any practical utility apart from showing the working of pointers?

Yes, that specific technique is highly employed in viruses for code injection.

"C programmer use this kind of code where a int pointer has been declared first and assigned a value inside a function?
"

These kind of programming is employed widely in embedded systems where a memory manager gives a memory and applications use it to fill it somewhere else.

Thank you very much for your reply. Although I don't have
much knowledge on advance use of pointer but I have got
a clue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.