[英]How to pass an array to a function in c
我是C ++編程的新手,只是了解數組。 我試圖將數組用作函數的參數,但程序無法編譯。 更具體地說,這是我的代碼:
int main ()
{
int values [10],i;
cout<<"Enter 10 values: "<<endl;
for (i=0; i<10;i++)
{
cin>>values[i];
}
// This is the function to which I want to send the array.
getmaxmin (values, 10);
}
我收到一條錯誤消息:“函數main中未解析的外部符號”。 這意味着什么?
謝謝!
在使用函數並定義任何已聲明的函數之前,是否已聲明函數?
int function();//declaration
//...
function();//call
//...
int function()//definition
{
//do stuff
}
首先在調用函數之前先聲明它,
int getmaxmin(int values[10]); //Prototype
getmaxmin (values); // Call
int getmaxmin (int values[10])
{
// Define
}
通過這種方式,您可以在C ++中傳遞數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.