CJCoding With Joseph
15free / daySign inCreate account

Array of Pointers to Heap Words

Read an integer n, then n words. Allocate an array of n char* on the heap, give every word its own heap copy, and print:

- one line per word, formatted "<index>: <word>", with indexes starting at 0
- a final line "Longest: <word>" naming the word with the most characters

If two words tie for the longest, report the one that came FIRST.

For the input:

3
red blueberry kiwi

the output is exactly what is shown in Expected Output.

Free the memory you allocate before the program ends — this question checks for memory leaks.

Expected Output:

0: red
1: blueberry
2: kiwi
Longest: blueberry

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Pointers
📥 Auto-Input:
3\nred blueberry kiwi\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.