I've seen several occurrences in tutorials where i variables with an "m" in front of the actual name. At first I thought it meant "my" but after really keeping a lookout for these "m"'s I'm no longer sure what it means. Does anyone know where this convention comes from?
5 Answers
m
is to indicate that it is a member variable, it is common variant on Hungarian Notation. Other common prefixes to look out for are I
for interface and C
for class.
Depending on the language, it is also common to prefix s
for string and b
to indicate a boolean.

- 20,275
- 4
- 64
- 80
-
I thought the s prefix was for static – Anon Jan 11 '15 at 06:24
-
1It can also be a prefix for `static`. In C/C++, JS, Python I have seen it used for `string`. It depends on the language. – Dennis Jan 11 '15 at 06:35
It's commonly used to mean that variable is a member of class. For example it's useful in situations like this:
someclass::somefunc()
{
...
.
.
m_myvar = 1;
lvar = 2;
.
.
.
}
You can tell at a glance that m_myvar
is a member of someclass
but lvar
is not.

- 11,704
- 6
- 44
- 58
One common use for m
as a prefix is "member", as in a member of a class in an object-oriented language.

- 776,304
- 153
- 1,341
- 1,358
-
Thank you, that makes perfect sense, even obvious when i think about :) – Daniel Figueroa Sep 10 '11 at 09:33
There is no established convention on what variable names can mean, especially their prefixes.
Basically the camel casing with the first small letter normally indicates a local variable, existing only in the current execution scope. Here m can stand for "module variable", e.g. the variable that exists only in the given module and that is not global. But this is just a guess.

- 12,086
- 12
- 63
- 115
It is probably a slight variant on what is called Hungarian Notation, which encodes some type information in the variable name.
As mentioned by the other posters an "m" would usually be used to indicate the variable is a class member.

- 2,392
- 1
- 18
- 19