#include <stdio.h>
void add_adjacents() {
int num1[5] = {1, 2, 3, 4, 5};
int num2[5] = {10, 20, 30, 40, 50};
int final[5];
for (int i=0; i<sizeof(num1); i++) {
final[i] = num1[i] + num2[i];
}
for (int c=0; c<sizeof(final)/sizeof(final[0]); c++) {
printf("%d\n", final[c]);
}
}
void main() {
add_adjacents();
}
So, I did the above without the pointers. But with pointers, here is my attempt: I'm still new to pointers, and I'm playing with different practice problems.
#include <stdio.h>
void add_adjacents() {
int num1[5] = {1, 2, 3, 4, 5};
int num2[5] = {10, 20, 30, 40, 50};
int final[5];
for (; *num1 != '\0'; *num1++) {
*final = *num1 + *num2;
}
for (int c=0; c<sizeof(final)/sizeof(final[0]); c++) {
printf("%d\n", final[c]);
}
}
void main() {
add_adjacents();
}
i<sizeof(num1)-->i<sizeof(num1)/sizeof(*num1)*num1++:num1is array, not pointer.*num1 != '\0':0is not included in the array ofnum1