What is a pointer value and address?

28 Dec 2022 Balmiki Mandal 0 C Programming

Understanding Pointer Value and Address in C Programming

A pointer value is a data object that refers to a memory location. Each memory location is numbered in the memory. The number attached to a memory location is called the address of the location.

In C and C++ programming, a pointer is a variable that stores the memory address of another variable. The pointer value is the value stored in the pointer variable, which is the memory address of the variable it points to. The pointer address is the memory address where the pointer variable itself is stored.

For example, consider the following code snippet:

int x = 10;
int* ptr = &x;

In this code, we declare an integer variable x and initialize it to 10. We also declare a pointer variable ptr of type int* and assign it the address of x using the & operator. Now, ptr points to the memory location where x is stored.

The value of ptr is the memory address of x, which can be accessed using the * operator to dereference the pointer:

printf("Value of x: %d\n", *ptr); // Output: Value of x: 10

The address of ptr itself can be obtained using the & operator:

printf("Address of ptr: %p\n", &ptr); // Output: Address of ptr: 0x7ffcbb6a8468 (address may vary)

In summary, the pointer value is the memory address it points to, while the pointer address is the memory address where the pointer variable itself is stored.

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.