运行 ❯
获取你
自己
的网站
×
更改取向
更改主题,深色/亮色
前往 Spaces
#include <stdio.h> #include <stdlib.h> int main() { int *ptr1, *ptr2; // Allocate memory ptr1 = malloc(4); // Attempt to resize the memory ptr2 = realloc(ptr1, 8); // Check whether realloc is able to resize the memory or not if (ptr2 == NULL) { // If reallocation fails printf("Failed. Unable to resize memory"); } else { // If reallocation is sucessful printf("Success. 8 bytes reallocated at address %p \n", ptr2); ptr1 = ptr2; // Update ptr1 to point to the newly allocated memory } return 0; }
成功,8 字节已重新分配到 0x5640317512a0 地址