Usually completion happens in the minibuffer. But one kind of completion is available in all buffers: completion for symbol names.
The character M-TAB runs a command to complete the partial symbol before point against the set of meaningful symbol names. Any additional characters determined by the partial name are inserted at point.
If the partial name in the buffer has more than one possible completion and they have no additional characters in common, a list of all possible completions is displayed in another window.
In most programming language major modes, M-TAB runs the command complete-symbol, which provides two kinds of completion. Normally it does completion based on a tags table (Section 24.16); with a numeric argument (regardless of the value), it does completion based on the names listed in the Info file indexes for your language. Thus, to complete the name of a symbol defined in your own program, use M-TAB with no argument; to complete the name of a standard library function, use C-u M-TAB. Of course, Info-based completion works only if there is an Info file for the standard library functions of your language, and only if it is installed at your site.
In Emacs-Lisp mode, the name space for completion normally consists of nontrivial symbols present in Emacs--those that have function definitions, values or properties. However, if there is an open-parenthesis immediately before the beginning of the partial symbol, only symbols with function definitions are considered as completions. The command which implements this is lisp-complete-symbol.
In Text mode and related modes, M-TAB completes words based on the spell-checker's dictionary. Section 15.4.