Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

Realloc in C language

#include <stdio.h>
#include <stdlib.h>
int main()
{
int *ptr = (int *)malloc(sizeof(int)*2);
int i;
int *ptr_new;
	
*ptr = 10;
*(ptr + 1) = 20;
	
ptr_new = (int *)realloc(ptr, sizeof(int)*3);
*(ptr_new + 2) = 30;
for(i = 0; i < 3; i++)
	printf("%d ", *(ptr_new + i));

getchar();
return 0;
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Realloc #C #language
ADD COMMENT
Topic
Name
4+2 =