75.6k views
4 votes
Assign 5th location to 3; int *p; p=malloc(18*sizeof(int)); ______

A)*(p+3) = 4;
B)*(p+7) = 4;
C)*(p+2) = 3;
D)*(p+4) = 3;

User Iwekesi
by
7.8k points

1 Answer

1 vote

Final answer:

The correct code to assign the number 3 to the 5th location in the array is D)*(p+4) = 3.

Step-by-step explanation:

The question is asking which line of code assigns the number 3 to the 5th location (index 4, as indexing starts at 0) in an integer array that has been dynamically allocated.

The line C)*(p+2) = 3; assigns the number 3 to the 3rd location (index 2), not the 5th. The correct answer is D)*(p+4) = 3; as it assigns the number 3 to the 5th location (index 4) in the dynamically allocated array pointed to by p.

The correct code to assign the number 3 to the 5th location in the array is D)*(p+4) = 3.

User Tschale
by
8.6k points