You seriously need to know about scope and lifetime of variables.