I have a problem with the following code:
#include <stdlib.h>
#include <stdio.h>
void red(int *);
int main()
{
int *wsk,i;
wsk = (int*)malloc(10*sizeof(int));
for(i=0;i<10;i++)
{
wsk[i]=i+100;
printf("value: %d num pointer:%p \n",wsk[i],wsk+i);
}
printf("\n\n");
red(wsk);
printf("\n\n");
for(i=0;i<11;i++)
{
printf("value: %d num pointer:%p \n",wsk[i],wsk+i);
}
free(wsk);
return 0;
}
void red(int* wsk)
{
int i;
wsk = realloc(wsk,11*sizeof(int));
for(i=0;i<11;i++)
{
printf("value: %d num pointer:%p \n",wsk[i],wsk+i);
}
}
On the school computer this code works and the wsk
pointer in the function red is the same as in main. When I run the same code on a different computer I get different results
Results from my computer:
Results from the other computer: