A question here... Can I dynamically allocate memory to a pointer in main() by calling a function that do allocation of memory.
eg codes:
/*******************/
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
int mcalc(int* vect);
int main(){
int* ptr;
int i;
mcalc(ptr);
printf("ptr[3] = %i", ptr[3]);
return 0;
}
int mcalc(int* vect){
int x=0;
vect = (int*)malloc(10*sizeof(int));
for (x-0;x<10;x++){
vect[x] = x+1;
}
return 0;
}
/**********************/
Pls help. Thanks.
eg codes:
/*******************/
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
int mcalc(int* vect);
int main(){
int* ptr;
int i;
mcalc(ptr);
printf("ptr[3] = %i", ptr[3]);
return 0;
}
int mcalc(int* vect){
int x=0;
vect = (int*)malloc(10*sizeof(int));
for (x-0;x<10;x++){
vect[x] = x+1;
}
return 0;
}
/**********************/
Pls help. Thanks.