D
dam_fool_2003
Friends,
cannot we malloc a array?
So, I tried the following code:
int main(void)
{
unsigned int y[3]={1,3,6},i,j;
for(i=0;i<3;i++)
printf("before =%d\n",y);
*y = 7; /* 1*/
for(j=0;j<3;j++)
printf("after =%d\n",y[j]);
return 0;
}
In the above I derefered *y in the line indicated by1 (correct me if I
have used a wrong term since pointers are derefered in this way. But
in the above I have used array but derefered as a pointer since
an array always decays into pointers.) the array's first element value
changes. Considering this as a kind of proof that *y pointes to the
first element in a array I wanted to malloc the array y. I tried
various syntax but I only get warnings.
*y = malloc(sizeof y);
In spite of the warnings I have compiled the code and the code I not
have any run time error. Can somebody tell me the correct syntax?
By the malloc of above the array's first element's mem get
allocated, Am I correct?
What happens I we use a multi dimensional array?
cannot we malloc a array?
So, I tried the following code:
int main(void)
{
unsigned int y[3]={1,3,6},i,j;
for(i=0;i<3;i++)
printf("before =%d\n",y);
*y = 7; /* 1*/
for(j=0;j<3;j++)
printf("after =%d\n",y[j]);
return 0;
}
In the above I derefered *y in the line indicated by1 (correct me if I
have used a wrong term since pointers are derefered in this way. But
in the above I have used array but derefered as a pointer since
an array always decays into pointers.) the array's first element value
changes. Considering this as a kind of proof that *y pointes to the
first element in a array I wanted to malloc the array y. I tried
various syntax but I only get warnings.
*y = malloc(sizeof y);
In spite of the warnings I have compiled the code and the code I not
have any run time error. Can somebody tell me the correct syntax?
By the malloc of above the array's first element's mem get
allocated, Am I correct?
What happens I we use a multi dimensional array?