Code not working properly
Code not working properly
Hello @anshufirefox the main problem in your code is that you are trying to access elements by doing arr+1.
in this way you are incrementing 1 in the starting blocks address and this you can chek by priting the array elements it will produce random garbage values.
you to do this with indexing.
Here is the corrected code:
if you have any doubt you can ask here:
Happy Learning!!
Yeah so array being allotted a contiguous memory why is my way of accessing the elements being problematic?
No, I am asking. Why is it being problematic/
Look at this piece of code for example. This was written by Prateek Sir in one of the lectures. The idea is that if the address is updated by 1, so array being a contiguous memory, this way of accessing elements is working here. Why is this method being problematic in my code?
The above code is for recursive first occurrence of an element in an array.
This method is not wrong but the way you were doing i said that was wrong.
wait let me see your implementation again.
Found out the mistake probably, the mistake was in inputting the values i guess.
Hello @anshufirefox this is the corrected code:
you were taking values in input in wrong format.
it should be cin>>a[i] but you were doing cin>>a[n].
Happy Learning !!
Thank you, got it
hello @anshufirefox if you feel that your doubt is cleared you can mark this doubt as resolved .
Happy Learning!!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.