Aspirin prevents the blood in the body from clotting, and because stroke and heart attack are both caused by the formation of blood clots in the body, anything that prevents blood clotting from forming would be expected to have a beneficial effect in those diseases.
In women, aspirin prevents strokes and doesn't have any real effect on heart attack, and in men aspirin prevents heart attacks but has no effect on the prevention of strokes. So there appears to be a gender-based difference in the beneficial effect of aspirin.