Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do C and C++ programmers prefix variables with "g" and "k"?

I have noticed this recently in C and C++ libraries. It seems common to use gFoo and kBar as forms of variable names. I assume "g" means global, but does "k" mean constant? I noticed that Atom and Visual Studio Code both highlight these forms with a different color, which would be convenient if I could understand their meaning. Are there any more conventions for naming the scope of variables, rather than their type as with Hungarian notation?

Edit: I found others, but I have not yet found the grammar file in Atom which describes these variable names. enter image description here

like image 250
Vortico Avatar asked Oct 20 '25 13:10

Vortico


1 Answers

g and m are scope prefixes, global and member. k is used for constant because c was used for char. The other 2 prefixes in your example are f for float and s for static.

More important than the internet's opinion on variable naming conventions is your boss's opinion on them, if they say k stands for constant in German, that is what it stands for :D

like image 63
Brian Donahue Avatar answered Oct 23 '25 08:10

Brian Donahue



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!