Q:

Write a program to define an array of ten ints. Give each element the same value as its position in the array

0

Write a program to define an array of ten ints. Give each element the same value as its position in the array.

All Answers

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

int main() {
  int ia[10];
  for (size_t i = 0; i != 10; ++i)
    ia[i] = i;

  // To get the size of an array one could use
  //     sz = sizeof(ia) / sizeof(*ia)
  // However, this will not work for some situations like dynamically allocated
  // array, pointer array, array in function parameter etc.

  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