Answer to Question #256437 in C++ for sen

Question #256437

What is the data type of pointer variables? Suppose that we don‘t know the name of a variable but we do know its address. Can we access the contents of that variable? Explain briefly.



1
Expert's answer
2021-10-31T12:02:02-0400

What is the data type of pointer variables?

Pointers are used to operate directly on the memory area. Access of variables using pointers is faster rather than variable access by its declaration. A pointer is defined as below:

int x, *ptr;

ptr = &x;

*ptr = 3;

In above example, a variable x is declared as int type and corresponding a pointer is declared as *ptr. Next, ptr has been assigned the address of variable x as ptr = &x. Next *ptr is assigned as *ptr = 3

*ptr = 3 will assign the value in x as x = 3

*ptr = the value at the address contained in ptr.


Suppose that we don‘t know the name of a variable but we do know its address. Can we access the contents of that variable? Explain briefly.

The data using the pointer is always accessed using its address. For example, in the above case, the variable ptr holds the address of the data. Therefore using the address of the data variable, it can be accessed using *ptr.



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS