CJCoding With Joseph
15free / daySign inCreate account

Count Matches With a Pointer Walk

Scan an array with a MOVING POINTER rather than an index.

Read an integer n (at most 64), then n integers, then one more integer: the target. Work out how many elements equal the target, and the 0-based index of the FIRST element that equals it, or -1 if 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, then First 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
Topics:
Pointers
📥 Auto-Input:
7\n9 4 1 4 2 4 0\n4\n
This input is automatically fed to your program's stdin
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.