Originally Posted by
laserlight
You could say that, but it would be more accurate to say that you allocated memory for what i points to.
Just remember that since i is a pointer to int, *i is an int, so you assign
correct
Code:
#include<stdio.h> #include<stdlib.h>
int main (void)
{
int *i = (int*)malloc(1 * sizeof(int));
*i = 123;
printf("%d \n", i);
printf("%d \n", *(i));
printf("%p \n", &i);
return 0;
}
output
10949544
123
0061FF2C
Now If I want to assign value to array
I can't write
Code:
array[5] = {1,2,3,4,5}; //static array
How to assign array value
Code:
#include<stdio.h>#include<stdlib.h>
int main (void)
{
int size = 5, i=0;
int *array= (int*)malloc((sizeof(int)) * size);
for(i=0; i < size; i++)
{
}
return 0;
}