How do i pass an array function without using poin

2020-05-27 06:21发布

I have been asked in an interview how do you pass an array to a function without using any pointers but it seems to be impossible or there is way to do this?

标签: c
7条回答
等我变得足够好
2楼-- · 2020-05-27 06:56

Put the array into a structure:

#include <stdio.h>
typedef struct
{
  int Array[10];
} ArrayStruct;

void printArray(ArrayStruct a)
{
  int i;
  for (i = 0; i < 10; i++)
    printf("%d\n", a.Array[i]);
}

int main(void)
{
  ArrayStruct a;
  int i;
  for (i = 0; i < 10; i++)
    a.Array[i] = i * i;
  printArray(a);
  return 0;
}
查看更多
登录 后发表回答