Pay attention when you declared temp
as float temp[4] = ...
then the variable temp
by itself is of type float*
(pointer)
which means, the assignment arr = temp
would make arr
point to the same (static) array as arr
does.
You can play around with this by sending them to a function and observe the behavior.
i already made this demo for you:
#include <stdio.h>
#include <stdlib.h>
void printTmp(int n, int tmp[n]);
int main() {
printf(" in main\n");
int* arr= malloc(4*sizeof(int));
int temp[4] = {1,2,3,4};
arr = temp;
for(int i = 0; i < 4; i++) {
printf("%d, ",arr[i]);
}
printTmp(4, temp);
printTmp(4, arr);
return 0;
}
void printTmp(int n, int tmp[n]) {
printf("\n \n in Print\n");
for(int i = 0; i < n; i++) {
printf("%d, ", tmp[i]);
}
}
which yields the output:
in main
1, 2, 3, 4,
in Print
1, 2, 3, 4,
in Print
1, 2, 3, 4,