Compiled this way, it will show the array's contents successfully transferred to the newarray in Main. But, you un-comment the print statement and recompile, you'll get zeroes for the newarray's contents!!!
Code:
#include <stdio.h>
double * createarray(void);
int main(void)
{
double newarray[3][5] = {0.0};
double * ptr;
int count, total;
ptr = createarray();
// printf("\n\nThis is a TEST print statement!\n\n");
for(total = 5, count = 0; count < total; count++)
newarray[0][count] = *((ptr) + count);
printf("\nTest of Main array content transfer:\n");
for(total = 5, count = 0; count < total; count++)
printf("%.2lf \n", newarray[0][count]);
return 0;
}
double * createarray(void)
{
int count, total;
double array[3][5];
double * createptr = 0;
printf("Each time I prompt you, please enter five floating point values.\n");
printf("Enter *only* your first row of five floating point numbers, please.\n");
for(total = 5, count = 0; count < total; count++)
scanf("%lf", &array[0][count]);
printf("\nTest of original array's contents [first row only]:\n");
for(total = 5, count = 0; count < total; count++)
printf("%.2lf \n", array[0][count]);
createptr = array;
printf("\nTest of original ptr's contents:\n");
for(total = 5, count = 0; count < total; count++)
printf("%.2lf \n", *((createptr) + count) );
return createptr;
}