How do you print the data from an address in the C language?

To print the data in an address, use pointers to access the contents at the address. Here is a simple example code demonstrating how to print the data at the address.

#include <stdio.h>

int main() {
    int num = 10;
    int *ptr = &num;

    printf("Value at address %p is %d\n", ptr, *ptr);

    return 0;
}

In this example, we first define an integer variable num, then use the & operator to get the address of this variable and assign it to a pointer ptr. We then use the printf function to print the address of the pointer ptr and access the data at that address through the pointer. In the printf function, %p is used to print the address of the pointer, and %d is used to print the data at the address.

By doing this, it is possible to print the data in the address.

bannerAds