How is the statement of retained earnings prepared? What is the purpose of closing entries? What accounts are not affected by closing entries? Explain and provide examples

How is the statement of retained earnings prepared? What is the purpose of closing entries? What accounts are not affected by closing entries? Explain and provide examples.