Please help urgently!!! Error in passing of values to function

Error in passing of values to function to search for an element in a 1d array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
void search(int,int,int);
int A[20],size,num,i;
cout<<"\nEnter the number of elements in the array:";
cin>>size;
cout<<"\nEnter the elements of the array:";
for(i=0;i<size;i++)
cin>>A[i];
cout<<"\nEnter the element to be searched for:";
cin>>num;
search(A,size,num);
getch();
}
void search(int Arr[],int s,int n)
{
int j,loc,flag=0;
for(j=0;j<s;j++)
if(Arr[j]==n)
{
flag=1;
loc=j;
break;
}
if(flag==0)
{
cout<<"\nElement not found";
}
else
cout<<"\nElement found at position "<<(loc+1);
}
Last edited on
1) DO not place function declaration inside another function. It is awful thing which made its way in C++.

2) Your declaration and definition does not match:
declaration: void search(int,int,int);
definition: void search(int Arr[],int s,int n) essentually void search(int*, int, int) signature
Topic archived. No new replies allowed.