-1
所以我被要求編寫一個程序,該程序使用指向數組中第一個元素的指針並將指針傳遞給函數。然後僅使用指針變量(和循環結構),只打印數組值是7。這裏精確倍數該腳本:無法使用指針訪問數組中的某些值
#include <iostream>
using namespace std;
void print_sevens(int *nums,int length){
for(int i = 0; i < length; i++){
nums = nums + i;
if(*nums % 7 == 0)
cout << *nums << endl;
}
}
int main() {
int a[5]={7,49,2,8,70};
int *p1 = &a[0];
print_sevens(p1,5);
}
從這個輸出是:
-149462114
我找不出什麼是錯的。任何幫助表示讚賞。謝謝
爲什麼所有的downvotes? –