Practice mode C Language

What is printed by this C code: int m = {{1, 2, 3}, {4, 5, 6}}; printf(“%d”, *(*(m + 1) + 1));?

Correct answer A. 5

Explanation

m + 1 points to the second row {4, 5, 6} because m decays to a pointer to an array of 3 ints. Dereferencing gives that row, which decays to a pointer to its first element, and adding 1 moves to the second element, 5. So *(*(m + 1) + 1) is the same as m[1][1]. Answer 2 confuses the row step with a single int step.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.