Heya. I have yet another question about pointers and 2D arrays, this time dealing with strings (also, thanks to the guy who helped me last time, it was mighty useful).
When using ints I first allocated memory for the array of pointers, then allocated memory for each pointer, and in doing so clearly had X amount of pointers with X amount of space.
However, with strings, I did this:
char **d;
char *strOne = "Spoo!";
char *strTwo = "Fleemage.";
char *strThree = "Bruce Lee is awesome";
d = (char**)malloc(3*sizeof(strThree));
d[0] = strOne;
d[1] = strTwo;
d[2] = strThree;
strTwo = "Yo";
printf("%s\n", d[1]);
printf("%s\n", strTwo);
This works, but I want to know, is how d is storing it's array of pointers physically. Given that I hadn't allocated space, will it stick d[n] right after the point where d[n-1] ends, given the first thing it's assigned, since it doesn't ultimately know how many pointers it is holding?
When using ints I first allocated memory for the array of pointers, then allocated memory for each pointer, and in doing so clearly had X amount of pointers with X amount of space.
However, with strings, I did this:
char **d;
char *strOne = "Spoo!";
char *strTwo = "Fleemage.";
char *strThree = "Bruce Lee is awesome";
d = (char**)malloc(3*sizeof(strThree));
d[0] = strOne;
d[1] = strTwo;
d[2] = strThree;
strTwo = "Yo";
printf("%s\n", d[1]);
printf("%s\n", strTwo);
This works, but I want to know, is how d is storing it's array of pointers physically. Given that I hadn't allocated space, will it stick d[n] right after the point where d[n-1] ends, given the first thing it's assigned, since it doesn't ultimately know how many pointers it is holding?