answersLogoWhite

0

How do you do casting with pointers?

User Avatar

Anonymous

∙ 20y ago
Updated: 8/16/2019

The question posed is a bit difficult to answer as there are no context specific clues (are we talking C/C++ here, or something more general such as object references in Java?), so an answer relating to C is given. Many times when writing a program it becomes necessary to pass a reference to a piece of data to a function, or perhaps to store a reference to a piece of data -- especially when writing a data structure that stores references to many different data (of many different types). In such a case the easiest way is to create a void pointer reference (void*). Now "casting the pointer" in order to correctely dereference the data is simply a matter of knowing the data type you are casting to, and indicating that it is a reference to a piece of data of that type. For example, suppose you have a structure called foo, that contains a field called bar, then: void printbar(void* myfoo) { printf("Bar = %s\n", (struct foo*)myfoo->bar); } should solve your problem. In this example you are indicating that the void pointer myfoo (which holds a memory reference) should be cast to a pointer that holds a memory reference to a piece of data of the type stuct foo.

User Avatar

Wiki User

∙ 20y ago

What else can I help you with?

Related Questions

What are void pointers?

They are pointers without type


Where the pointers are used?

POINTERS ARE USED TO STORE ADDRESS


What are the background pointers in java?

Java does not support pointers.


Pointers are replaced by what in java?

Nothing. Java does not have a concept that is equivalent to Pointers.


How do you get score 6?

3 two-pointers or 2 three-pointers


How do you cast confringo Harry Potter Deathly Hallows part1?

first you need to find the spellbook thing by casting four pointers to lead you to it. you will need to fight off some death eaters before getting the book. If the four pointers keep leading you back to the rocks, then you may have to start the level over. That happened to me. But it only restarts from where you first found the rocks, so dont worry


Why laser mouse are used?

Because the laser pointers are much easier to use than the ball pointers. The ball pointers are often difficult to move around while the laser pointers can move in any direction without "getting stuck"


Can labs be trained as pointers?

Yes, some labs are trained as pointers, and some as retrievers.


Can you use pointers in java?

Java does not support Pointers and hence you cannot use it in Java.


How many three-pointers did LeBron James make?

he made about 130,000 three pointers


How casting is done?

Metal casting can be done thro sand casting ,investment casting , pressure die casting methods


Which are the possibe arithmetic operation with pointers?

Pointers in C are stored as integers. You can perform any mathematical operations on pointers that you can perform on ints.Of course not, the following operations are possible: =, +, +=, ++, -, -=, --, *, [], ->, typecast