数组和指针的区别
//head.h
#define ARRLEN 1024
int arr[ARRLEN]
//main.cpp
#include<iostream>
#include"head.h"
using namespace std;
extern int *arr; //this is error
//extern int arr[]; //this is ok
int main(void)
{
for (int i=0;i<ARRLEN;i++)
{
arr[i] = i;
}
for (int i=0;i<ARRLEN;i++)
{
cout<<arr[i]<<endl;
}
return 0;
}
COMPILE ERROR MESSAGE AS FOLLOWS
main.cpp:5:13: error: conflicting declaration ‘int* arr’
extern int *arr; //this is error
^
In file included from main.cpp:2:0:
head.h:4:5: error: ‘arr’ has a previous declaration as ‘int arr [1024]’
int arr[ARRLEN];