Each major mode has its own syntax and syntax table. If you just put (modify-syntax-entry ?_ "w") in your init file, it gets evaluated in the buffer that is current when your init file is loaded -- not in a C/C++ buffer.
To evaluate that sexp when in a C/C++ buffer you can put it in a function, which you add to the mode hook. For example (untested):
Rather than modifying the syntax tables, you can instead use the built-in superword-mode:
Superword mode is a buffer-local minor mode. Enabling it changes
the definition of words such that symbols characters are treated
as parts of words: e.g., in ‘superword-mode’,
"this_is_a_symbol" counts as one word.
You can enable it per mode using a a hook: (...
The problem has been reported as #99 and already fixed in master of mmm-mode, but since there is no new release, you have to install the newest mmm-mode manually, or add the missing setting to mmm-save-local-variables -- for example with use-package:
(add-to-list 'mmm-save-local-variables '(syntax-ppss-...