C++ 用引用的方式向函数传递数组

306 阅读1分钟

#include <iostream>
using namespace std;

int a[10] = { 10,20 };
void GetCharArr(char (&ac)[20])
{    
sprintf_s(ac, "ABABXX%d", a[0]);
}

int main()
{
char str1[20];

GetCharArr(str1);
printf("当前的字符串是:%s", str1);
system("PAUSE");
return 0;
}