Quote:
int addArray(int nums, int k){
This is wrong, because
nums
should be an array of integers (and, anyway, you need to pass the size of the array as well).
Try
#include <iostream>
int addArray(int num[], size_t num_size, int offset)
{
int temp = 0;
for(size_t n = 0; n < num_size; ++n)
{
temp = temp * 10 + num[n];
}
return (temp + offset);
}
int main()
{
int num[] = {1,0,0,0};
int res = addArray(num, sizeof(num)/sizeof(int), 300);
std::cout << res << std::endl;
}
Note, you might also write:
#include <iostream>
#include <numeric>
int main()
{
int num[] = {1,0,0,0};
int result = 300 + std::accumulate( std::begin(num), std::end(num), 0, [](int a, int b){ return a*10 + b; });
std::cout << result << std::endl;
}