← Back to Pointers
Question 468
Count Matches With a Pointer Walk
Count Matches With a Pointer Walk
Scan an array with a MOVING POINTER rather than an index. Read an integern(at most 64), thennintegers, then one more integer: thetarget. Work out how many elements equal the target, and the 0-based index of the FIRST element that equals it, or-1if the target never appears. Get that index by subtracting pointers (p - values), not with a separate counter. Print exactly two lines:Count:followed by the number of matches, thenFirst index:followed by that index. For the input: 7 9 4 1 4 2 4 0 4 the output is exactly what is shown in Expected Output. Each line ends with a newline.
Expected Output:
Count: 3 First index: 1
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.