#include<iostream.h>
int liner(int [], int ,int );
void main ()
{
	int a[1000];
	int arraysize,element;
int searchkey;
cout<<"Enter how many elements in your array";
cin>>arraysize;
cout<<"enter the elements of the array ";
for(int i=0;i<arraysize;i++)
cin>>a[i];
cout<<"Enter the searchkey";
cin>>searchkey;
element=liner (a,searchkey,arraysize);
if (element!=-1)
cout<<"::::Found value in index \n"<<element<<"\n";
else 
cout<<"::::value not found :::::\n";
}
int liner(int array[], int key ,int size){
	int index=-1;
	for(int n=0;n<size;n++)
		if (array[n]==key)
			index =n;
		return index;
}

is this code true .
i search about the value .and return its index
but how i can input index and return its value

I'm not sure what you mean by extract a value. Do you mean get the value?

This gets the value of the nth element of array.

int value = array[n];

A note on style, search functions usually return the address of first element match. Your function returns the value of the last one. Why does this matter? Well if you return the address of the first match, it gives a point to search for more matches.

yes i mean get value ..
i should to search about the value if its there or not .
also to get avalue from adress i should to chick if the adress is out of memmory

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.