Browse Source

begin adding code examples of pointers & multidimensional arrays

master
T. Meissner 11 years ago
parent
commit
7d474d40bc
1 changed files with 10 additions and 2 deletions
  1. +10
    -2
      c_pointers/chapter_4.c

+ 10
- 2
c_pointers/chapter_4.c View File

@ -72,18 +72,26 @@ int main(void) {
displayArrayPtr(vector, sizeof(vector)/sizeof(int)); displayArrayPtr(vector, sizeof(vector)/sizeof(int));
// using one-dimensional array of pointers
// using a one-dimensional array of pointers
{ {
int *arr[5]; int *arr[5];
for (size_t i = 0; i < 5; i++) { for (size_t i = 0; i < 5; i++) {
// both variants are equivalent // both variants are equivalent
arr[i] = (int*) malloc(sizeof(int));
arr[i] = malloc(sizeof(int));
*arr[i] = i; *arr[i] = i;
//*(arr + i) = (int*) malloc(sizeof(int)); //*(arr + i) = (int*) malloc(sizeof(int));
//**(arr + i) = i; //**(arr + i) = i;
} }
} }
// pointers and multidimensional arrays
{
int matrix[2][5] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}};
for (size_t i=0; i<2; i++) {
}
}
return 0; return 0;
} }

Loading…
Cancel
Save