Do we have a teardown() function on the same lines of setup() function

Greetings,
I am making a speedometer cum odometer using Arduino UNO, a 128*64 LCD and a reed switch for my motorbike.
My query is that do we have any kind of teardown() function in Arduino that I could override in my sketch to write some clean-up stuff like persisting odo reading to EEPROM?
Any other callback function that gets invoked immediately before Arduino is disconnected from power would also serve my purpose.

vikalpsetya:
function that gets invoked immediately before Arduino is disconnected from power

How would it know until it was too late?

Short answer, nope.

An option would be to give the Arduino a (super) cap as backup and detect when the normal power is disconnected and run your function.

you could make a circular buffer in EEPROM and just write every mile.

I didn't do the math, but with a 24bit number you could put at least a million writes to EEPROM if you are leveling

Any other callback function that gets invoked immediately before Arduino is disconnected from power would also serve my purpose.

That would be a neat trick. How would the program know that you were about to turn off the power ?

You could write your own "teardown()" function and invoke it with say a pushbutton. The function could control a relay or transistor that supplies power to the Arduino so could turn it off. You would, however, then need a mechanism to turn it on again.

What everyone else said. When - under what set of conditions - would such a teardown() function be invoked? Silicon ain't psychic.

Silicon ain't psychic.

It's psychotic.