answersLogoWhite

0


Best Answer

You cannot physically convert variables of one type to another type, you can only cast them to create a new type (a new variable), providing the new type is covariant with the existing type.

int i = 100; // int variable

int* p = &i; // pointer to int

The indirect value of p is i (100) while the direct value of p is the address of i. And because p is a variable, it has an address of its own. Thus converting the pointer p to an int can be done in one of three ways:

int j = *p; // assign indirect value of p to j (thus j==100).

int k = (int) p; // cast the address stored in p and assign to k (k==address of i)

int l = (int) &p; // cast the address of p and assign to l (l==address of p)

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in c plus plus that will convert an integer pointer into an integer and viceversa?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the code of a c program that will read in a positive integer value and determine If the integer is a prime number and If the integer is a Fibonacci number?

see the program


What is program counter?

Synonym for Instruction Pointer.


What is meant by an pointer in c program?

Pointer is like variable address the members in memory shell


What happens when java program attempts to divide one integer by another?

In that case, unless you specifically convert ("cast") at least one of the numbers to a double or float, the result will also be an integer. Example: 1 / 3 = 0


What is the difference between stack pointer and program counter?

The stack pointer keeps track of the top of the stack used by the current thread. The program counter keeps track of the next instruction in a program. Both are registers and both store a memory address.


What is the purpose of pointer in C?

the purpose of pointer in c for saving the memory space.,and reduce the length and complexity of the program


Write a program to subtract integer y from integer x?

x -=y;


C program pointers to pointers examples?

Pointer to Pointer is a double pointer, denoted by (**). Pointer stores the address of the variable and pointer to pointer stores the address of a pointer variable and syntax can be given as int **ptr2ptr;


What is the difference bw function pointer and function of pointer?

function pointer is a variable that hold the address of any function which declared in the program but function pointer is the array of the function that accept the run time size of the function.


What is null pointer assignment?

This error message means that somewhere in your program you have used a pointer-varible containing NULL-value. (Within an actual OS it with stop the program immediately, but in MS-DOS it doesn't.)


Function of a program counter?

Program Counter is just a synonim for Instruction Pointer.


Your mouse pointer shows busy icon and it flickers how can you solve your problem?

This problem can be solved by waiting for the computer to finish executing the program. If it persists, it is usually due the program crashed, and the mouse pointer can be restored by terminating the program using Task Manager.