0

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;
    }
4
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by dellat
1

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

Edited by gerard4143: n/a

Votes + Comments
Right
1

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.

Edited by N1GHTS: n/a

1

"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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.