Commonly Accepted Variable Name Formatting - C/C++

I realize that this can be a matter of preference, but I have noticed that variables names in a lot of code samples I've seen have a prefix of g_, s_, m_, or just _. Is this a commonly accepted practice, and what do these prefixes mean? Are there any others that would be good to know?


  • g_ is a global variable
  • s_ is a static
  • m_ is a member (an instance variable)
  • _ is either a member, or more specifically a private member (both usages turn up)

This is common enough that many developers know about it, although it is not (to my knowledge) universally accepted. I don't think you are missing any others.

Update: Integrating comments below for better visibility

  • _ can also be used to denote a local variable (this one really isn't "standard")
  • k can be used to denote a constant

Need Your Help

How to set up a form in a Spring app that pulls data from different tables

java spring spring-mvc

I'm developing a Spring web app and am hoping someone can give me some advice. Currently I've got a form that when submitted populates a simple POJO that is stored in a database. That POJO needs to...

How do I unpack various form of integers in a byte buffer in golang?

buffer go unpack

I need to extract various fields in a byte buffer. I came up with this solution:

Is there a compiler or IDE for C on Windows that's regarded as an industry standard?

c windows ide compiler-construction

Taking advice from this post, I purchased a copy of 'The C Programming Language' and am happily reading my way through.