Computer Programming
C Programming
Auditioning

How do you do casting with pointers?

454647

Top Answer
User Avatar
Wiki User
2006-01-23 13:00:45
2006-01-23 13:00:45

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.

1
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0

Related Questions

User Avatar

They are pointers without type

User Avatar

POINTERS ARE USED TO STORE ADDRESS

User Avatar

Java does not support pointers.

User Avatar

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

User Avatar

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

User Avatar

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

User Avatar

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.

User Avatar

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

User Avatar

3 two-pointers or 2 three-pointers

User Avatar

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

User Avatar

1. Basics of C 2. Pointers 3. Function Pointers 4. Pointers Arithmetic 5. Most Important playing with pointers. 6. Algorithm to Solve Problems

User Avatar

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

User Avatar

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

User Avatar

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"

User Avatar

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

User Avatar

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

User Avatar

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

User Avatar

no , laser pointers emit a lower wavelength of radiation

User Avatar

he made about 130,000 three pointers

User Avatar

You can define pointers to every data-type (including elementary types, structures, unions, arrays and function), plus you can define generic pointers as 'void *'.

User Avatar

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

User Avatar

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


Copyright ยฉ 2020 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.