Q:

Using pointers, write a program to set the elements in an array to zero

0

Using pointers, write a program to set the elements in an array to zero.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iterator>
#include <iostream>

int main() {
  int ia[10];
  for (const auto &e : ia)
    std::cout << e << ' ';
  std::cout << std::endl;

  for (int *bg = std::begin(ia), *ed = std::end(ia); bg != ed; ++bg)
    *bg = 0;

  for (const auto &e : ia)
    std::cout << e << ' ';
  std::cout << std::endl;

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now