运行结果:
may be you are right
may be you are right
Program ended with exit code:
Test.cpp
#include <iostream>
using namespace std;
template <typename T>
void show(T a, size_t);
template <typename T>
void show(T a);
int main() {
int a[] = {, , , , , , , , ,};
int b[sizeof(a) / sizeof(int)] = {}; // 建立同数组a相同大小的数组b并将其所有元素初始化为0
char aa[] = "may be you are right";
char bb[strlen(aa) + ]; // 多分配一个字节存储截止符'\0'
memcpy(bb, aa, strlen(aa) + );
memcpy(b, a, sizeof(a)); // 因为memcpy是逐字节拷贝,而数组b为int类型,拷贝的长度应为sizeof(a)
show(a, sizeof(a) / sizeof(int));
show(b, sizeof(b) / sizeof(int));
show(aa);
show(bb);
return ;
}
template<typename T>
void show(T a, size_t len) {
for (int i = ; i < len; i++)
cout << a[i] << ' ';
cout << endl;
}
template<typename T>
void show(T a) {
while ((*a) != '\0')
cout << *a++;
cout << endl;
}