Best Answer

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

โˆ™ 2006-01-23 13:00:45
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you do casting with pointers?
Write your answer...
Related questions

What is an array of pointers to pointers?


What are void pointers?

They are pointers without type

Where the pointers are used?


What are the background pointers in java?

Java does not support pointers.

When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?

As for pointers, I think you have to readjust them. Pointers are just variables that store a memory address in them. You can have as many pointers that point to a single location in memory as you want.

Why are they no pointers in java?

Pointers are a major source of memory leaks and errors. Keeping that in view, the Java language was designed without pointers.

What are types of casting?

Two popular types of casting include: metal casting and concrete casting. However, there's also resin casting as well as iron casting.

How is metal casting done?

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

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

Are Java objects pointers?

No. Java objects are not pointers. Java does not support the pointers concept. You cannot access the memory location of the java objects.

Which is not the typical casting process?

Die casting.

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"

If your dog is a pointers and shedding a lot is this normal?

Pointers shed like normal dogs

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

What is the difference between array of pointers and pointer to an array?

An array of pointers is that for eg if we have array of 10 int pointers ie int *a[10] then each element that which is stored in array are pointed by pointers. here we will have ten pointers. In pointer to an array for eg int(*a)[10] here all the elements that is all the ten elements are pointed by a single pointer.

Most 3 pointers in a high school basketball game?

Marina High School holds the title with 384 3 pointers in a season and 29 3 pointers in a game.

What is the difference between lost wax casting and investment casting?

Lost wax casting and investment casting are two names for the same thing

What is the minimum number of additional pointers will be needed to reverse a singly linked list?

3 pointers...

What are restricted pointers in C99?

Using this you specify that two pointers can't point on the same address

How pointers are used in java?

They aren't. Java uses the (safer) idea of references instead of pointers.

What are five safety pointers for use in electronic shop work?

safety pointers in electric shop

Are gamma rays used in laser pointers?

no , laser pointers emit a lower wavelength of radiation

Study guides

Create a Study Guide