it give me error that initializing argument 2 of bool (int*,int*,int)
what is that mean?
i heard that if we didnt use the pointer is much eaiser but idk
Here's one way to initialize it. When you pass ptr to the function, you're doing this:
FindElement (array,*ptr,size );
When you use * now, you're derferencing the pointer. So now your sending the value at the address that ptr holds rather than the pointer itself. So, initialize the pointer and then drop the asterisk in the function call.
even when i did that i got the same error! for the element in the main!
if int* ptr=ptr have no meaning then how can i know the element which is in the array is there?
Sorry, I don't understand your question. I can see you've changed from using an int* to an int argument, but you're still comparing the value of array[i] to element without ever having given element a value in the first place.
What is it you want to do with element? What is it supposed to be set to?
yea.. i used the pointer from the beginning to let it check whether the value is in the array if not ptr++ move to the next element in the array and so on that what i understand from the question let me post the question
Write a recursive function that returns true if certain key exists in an
array, false otherwise.
Hints:
• You may assume a fixed size for the array.
• array can be filled with any data you like, and the key to search is
upon your choice.
You don't even need a pointer for this then. You can just pass the array. But if you insist, then all you need to do is:
int* ptr = arr;
And now your pointer will point to the first element of the array, and using pointer arithmetic you can traverse the array. This is pretty unsafe though, much better just to use the array by itself, or even better would be a vector.
int* ptr = arr; i tried that before but its not working too ok if i wont use the pointer anymore then how i will find the element!
if i put size++ in order to move to the next element that will change the size itself! well the array size wont be able to change once we initialize it..
or array[10]++! it wont work