0% found this document useful (0 votes)
50 views1 page

Let Us Compile and Run The Above Program That Will Produce The Following Result

This C program demonstrates the use of malloc(), realloc(), and free() functions to dynamically allocate and manage memory for a character string. It first allocates 15 bytes for the string "tutorialspoint", then reallocates to 25 bytes to add ".com" to the end. It prints the string and address each time to show the memory has changed with reallocation. The program ends by freeing the memory.

Uploaded by

ShivaJps
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views1 page

Let Us Compile and Run The Above Program That Will Produce The Following Result

This C program demonstrates the use of malloc(), realloc(), and free() functions to dynamically allocate and manage memory for a character string. It first allocates 15 bytes for the string "tutorialspoint", then reallocates to 25 bytes to add ".com" to the end. It prints the string and address each time to show the memory has changed with reallocation. The program ends by freeing the memory.

Uploaded by

ShivaJps
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>

#include <stdlib.h>

int main () {

char *str;

/* Initial memory allocation */

str = (char *) malloc(15);

strcpy(str, "tutorialspoint");

printf("String = %s, Address = %u\n", str, str);

/* Reallocating memory */

str = (char *) realloc(str, 25);

strcat(str, ".com");

printf("String = %s, Address = %u\n", str, str);

free(str);

return(0);

Let us compile and run the above program that will produce the following
result −
String = tutoria

You might also like