# Find a Fixed Point (Value equal to index) in a given array in C++ Program

C++Server Side ProgrammingProgramming

In this tutorial, we are going to solve the following problem.

Given an array, find the number which is equal to the index. It's a straightforward problem.

Iterate over the given array and return the index which is equal to the array element.

## Example

Let's see the code.

Live Demo

#include <bits/stdc++.h>
using namespace std;
int linearSearch(int arr[], int n) {
for(int i = 0; i < n; i++) {
if(arr[i] == i) {
return i;
}
}
return -1;
}
int main() {
int arr[] = {10, 20, 30, 40, 50, 5, 60};
cout << linearSearch(arr, 7) << endl;
return 0;
}

## Output

If you run the above code, then you will get the following result.

5

## Conclusion

If you have any queries in the tutorial, mention them in the comment section.
{"ft_lang_label":"__label__en","ft_lang_prob":0.67584544,"math_prob":0.9786002,"size":670,"snap":"2021-31-2021-39","text_gpt3_token_len":189,"char_repetition_ratio":0.10660661,"word_repetition_ratio":0.016129032,"special_character_ratio":0.32686567,"punctuation_ratio":0.18791947,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99717444,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-18T01:15:28Z\",\"WARC-Record-ID\":\"<urn:uuid:63e68112-e648-4490-9888-aae3e09e8de4>\",\"Content-Length\":\"32232\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:26071d87-b9c7-406d-90f7-9d21836c87a5>\",\"WARC-Concurrent-To\":\"<urn:uuid:cbf94cd7-a76f-4394-a25b-3c1f1b935009>\",\"WARC-IP-Address\":\"72.21.91.42\",\"WARC-Target-URI\":\"https://www.tutorialspoint.com/find-a-fixed-point-value-equal-to-index-in-a-given-array-in-cplusplus-program\",\"WARC-Payload-Digest\":\"sha1:PX75JYEAEQ2GJ52NYMQC2S6ALF5F34PZ\",\"WARC-Block-Digest\":\"sha1:GGKY53I64UTA4NO6DPG5CLTQXMYFO2XH\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780056120.36_warc_CC-MAIN-20210918002951-20210918032951-00098.warc.gz\"}"}