#include <iostream>
using namespace std;
int main()
{
int i;
int smallest;
int nums[5] = {4, 20, 18, 7, 2};
smallest = nums[0];
for (i = 1; i < 5; i++) {
if (nums[i] < smallest)
smallest = nums[i];
}
cout << smallest;
return 0;
}
I'm trying to do the same code but with pointers instead, but something is wrong, I don't know what it is.
Can someone help?
Thanks,
Here it is:
#include <iostream>
using namespace std;
int main()
{
int* pInt;
int* pSmallest;
int nums[5] = {4, 20, 18, 7, 2};
pSmallest = nums;
for (*pInt = 1; *pInt < 5; pInt++) {
if (nums[pInt] < *pSmallest)
pSmallest = pInt;
}
cout << pSmallest;
return 0;
}

New Topic/Question
Reply



MultiQuote






|