← Back to Pointers
Question 460
Multiplication Grid Through an int Double Pointer
Multiplication Grid Through an int Double Pointer
Build a two-dimensional grid on the heap using a double pointer (int **): an array ofrowsrow pointers, each owning its own block ofcolsints. Read two integers from input on the first line:rowsandcols. Fill the grid with a multiplication table — the value at rowr, columnc(both 0-based) is(r + 1) * (c + 1)— then print it, one row per line, with the values on a row separated by a single space and no trailing space. For the input: 3 4 the output is exactly what is shown in Expected Output. Each line ends with a newline. Print nothing else — no headings, no "Freed" message. Free the memory you allocate before the program ends — this question checks for memory leaks: every row block, and the array of row pointers.
Expected Output:
1 2 3 4 2 4 6 8 3 6 9 12
= 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.