On Mon, Aug 4, 2008 at 11:51 AM, raj_duttaphookan <[EMAIL PROTECTED]> wrote: > I want to know the following: > > A pointer is a special type of variable which holds the memory address > of an int variable or a float variable or a char cariable etc. But all > it holds is the memory address which is of same type
Not all memory addresses need be the 'same type' - indeed, The Standard allows for pointers to different types to be different sizes. > irrespective of > whether that memory address belonging to an int variable or a float > variable or a char variable. Yet we always have to define the pointer > as of the type of the variable it points to. Why can't we simply > define it as a pointer. In C you have void* if this is the sort of behaviour you require. (In C++ you must cast to it.) > It shall anyway hold the memory address and > later on while dereferencing it, it shall automatically dereference it > depending on whether the memory address it contained was that of an > int or a float or a char etc. But what if you defined it as containing a float pointer, but subsequently attempt to access it as if it were an int pointer? -- PJH 'Two Dead in Baghdad' not 'product-friendly' - Kent Ertugrul, chief executive of Phorm. http://shabbleland.myminicity.com
