Hi,
Could anyone please explain how the memory allocatio is done in case of double pointers?

Hi,
Could anyone please explain how the memory allocatio is done in case of double pointers?

int var = 10 ;
int *pvar = &var;
int **ppvar = &pvar;

here var is 10. and this will be stored in some memory say that is
1000 (i.e &var =1000)
so
var =10
&var =1000

to store &var we need a pointer ,
so we declared variable pvar then stored &var 1000 in that

so
pvar = 1000
now pvar is also a variable it also stores at some location
say that is 2000
&pvar = 2000
now i want to store the address of a poiner variable i require a pointer to pointer .
so i declared ppvar
hence
ppvar =&pvar,
now
ppvar is also a variable so it also gets some memory so lets say that is 3000
so
ppvar = 2000
&ppvar = 3000

now if i want to access either var or pvar i can do that by using ppvar
say

printf(" %u",var);
printf(" %u\n",*pvar);
printf(" %u\n",**ppvar);
all gives you only 10

printf(" %u\n",&var);
printf(" %u\n",ppvar);
printf(" %u\n",*ppvar);
gives you 1000

printf(" %u\n",&ppvar);
printf(" %u\n",ppvar);
gives you 2000
printf(" %u\n", &ppvar);
gives you 3000.

the results may vary taken just for simplicity

Thanks for the reply.Its clear now.I want to build a small project in c which includes both graphics and pointer concepts using LINUX OS.Could you please let me know how can i proceed on this?

Thanks for the reply.Its clear now.I want to build a small project in c which includes both graphics and pointer concepts using LINUX OS.Could you please let me know how can i proceed on this?

pointers and graphics:
no good idea:
may be you can start learning ncurses and try with them

pointers and graphics:
no good idea:
may be you can start learning ncurses and try with them

Thanx but i want to improve knowledge on C with pointer.

printf(" %u\n",&ppvar);
... gives you 2000

You have one 'p' too many. :)
printf(" %u\n",&ppvar); //prints 3000
printf(" %u\n",&pvar); //prints 2000

SDL is mainly for game development (and sometimes for other multimedia stuff as well) and is quite popular I think. Now, it depends on what kind of job you are looking for... If you are interested in making applications with GUI under Linux, I think GTK is very good. For 3D stuff, OpenGL is probably a "must-known", etc...

This article has been dead for over six months. Start a new discussion instead.