When a player makes a foul gesture in a basketball match, how to judge which side has the ball?

A player fouled in a basketball match. If the defender fouls, the ball belongs to the attacker. If the offense is fouled, the ball belongs to the defender. Where the ball should be, the referee will point his hand at the attacker. That is, the frontcourt of that side.

For example, if the attacker fouls from left to right, the referee's gesture will point to the left. The opponent's foul points to the right.