In: Computer Science
I'm having trouble determining the lines of code for 4-6
#include <stdio.h>
//function prototypes
void initializeArray(int size, int ids[]);
void printArray(int size, int * idPointer);
int main(void) {
// 1. declare an array of 5 integers called ids
int ids[1,2,3,4,5];
// 2. declare an integer pointer called arrayPointer and
// initialize it to point to the array called ids
int *arrayPointer = ids;
// 3. call initializeArray() function sending to it
// 5 for the size and the array called ids
intializeArray(5,ids[]);
// 4. add 3 to the value at where arrayPointer is pointing to
*(arrayPointer + 3);
// 5. add 5 to the value at 2 locations past
// where arrayPointer is pointing to
// 6. call printArray() function sending to it
// 5 for the size and arrayPointer
return 0;
}
// This function initializes an array ids of size "size"
void initializeArray(int size, int ids[]) {
int i;
for (i = 0; i < size; i++) {
ids[i] = i * 100;
}
}
// This function prints an array of size "size". The array is
pointed at by idPointer
void printArray(int size, int * idPointer) {
int i;
for (i = 0; i < size; i++) {
// 7. finish the code for the printf() statement
printf("Element at index %d is %d\n", i);
}
}
#include <stdio.h> //function prototypes void initializeArray(int size, int ids[]); void printArray(int size, int * idPointer); int main(void) { // 1. declare an array of 5 integers called ids int ids[5]; // 2. declare an integer pointer called arrayPointer and // initialize it to point to the array called ids int *arrayPointer = ids; // 3. call initializeArray() function sending to it // 5 for the size and the array called ids initializeArray(5,ids); // 4. add 3 to the value at where arrayPointer is pointing to *(arrayPointer) += 3; // 5. add 5 to the value at 2 locations past // where arrayPointer is pointing to *(arrayPointer+2) += 5; // 6. call printArray() function sending to it // 5 for the size and arrayPointer printArray(5, arrayPointer); return 0; } // This function initializes an array ids of size "size" void initializeArray(int size, int ids[]) { int i; for (i = 0; i < size; i++) { ids[i] = i * 100; } } // This function prints an array of size "size". The array is pointed at by idPointer void printArray(int size, int * idPointer) { int i; for (i = 0; i < size; i++) { // 7. finish the code for the printf() statement printf("Element at index %d is %d\n", i,*(idPointer+i)); } }