How hook_form_alter() works in Drupal?
Yes, the code inside hook_form_alter() or hook_form_FORM_ID_alter() will be run when the $form array is being built, and before it is rendered.

All active modules that implement one of these two hooks will have their implementations called before the $form array is rendered. (They will be called in sequence according to their weights).

If you need to alter or manipulate the values being submitted by the form, you can use one of these two mentioned hooks to include in the $form array your custom #validate or #submit functions, where you can perform any kind of code processing you need.

A good source for finding examples of all these functionalities is the examples module, specifically around here.