#include <stdio.h>

int main() {
    int* address = (int*)0x12345678; // Replace 0x12345678 with the desired memory address

    // Write data to the memory address directly
    *address = 123;

    // Verify the written data by reading it back using the pointer
    printf("Value at memory address %p: %d\n", (void*)address, *address);

    return 0;
}
segmentation fault or a runtime error. The reason is that you are attempting
to access a memory address (0x12345678) that is not valid or accessible by 
your program.

In modern operating systems, memory addresses are protected, and processes 
are not allowed to access arbitrary memory locations directly. When you try
to access an invalid memory address, the operating system terminates your 
program to prevent any unintended consequences or security issues.

To avoid errors like this, you should only access memory addresses that are
within the valid address range for your program. Typically, memory addresses
are assigned by the operating system or the compiler during program
execution, and you should work with pointers that point to valid variables
or dynamically allocated memory.


#include <stdio.h>
#include <stdlib.h>

int main() {
    // Dynamically allocate memory for an integer
    int* address = (int*)malloc(sizeof(int));

    if (address == NULL) {
        printf("Memory allocation failed.\n");
        return 1;
    }

    // Write data to the memory address using the pointer
    *address = 123;

    // Verify the written data by reading it back using the pointer
    printf("Value at memory address %p: %d\n", (void*)address, *address);

    // Free the dynamically allocated memory
    free(address);

    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: