Yes if you feel real hunger before 40 days is up stop your fast correctly at the first opportunity. There's no need to rush and eat the first thing you see of course, you have time to go shopping or wait till morning if it's the middle of the night or another inappropriate time. But if you continue past true hunger your body starts to STARVE. Hunger means your body has run out of fuel and continuing not to eat after that is endangering your vital organs which will no longer have enough nutrients and fuel to function correctly. Also of course, with no fuel left you will end up with all sorts of problems and symptoms from the ensuing state of malnutrition.
40 days is an abstract goal, it doesn't mean anything. The ultimate goal of any fast is to fast to it's natural completion no matter if that is 5 days 50 days or 150, once that point is reach the fast must be ended.