www.xbdev.net
xbdev - software development
Sunday January 4, 2026
Home | Contact | Support | Tutorials - Tips - Secrets - for C and C++.. It does all the hard work for us.. | Tutorials - Tips - Secrets - for C and C++.. It does all the hard work for us..
     
 

Tutorials - Tips - Secrets - for C and C++..

It does all the hard work for us..

 



Statics - C and C++


Something worth learning and remembering is the static keyword!

What does it do, and how it effects your code if you use it?

There are 3 possible places you can use the static keyword that I know of, and they are:

static variable, e.g.:

static function, e.g.:

static class member function, e.g.:

Of course there's a few little differences between C and a C++ class static...they more or less do the same thing...but its how you initilise them that matters....of course after reading a few lines, you'll feel right at home with them....and one of the best things about static variables, is that you don't have to use globals....or your debugging can be made easier :)

Remember


Remember, statics are super cool! It's like when you're at a party, and there's this one person who's always there, no matter what. That's 'static' for ya! It's like, "Hey, I'm here to stay, party people!"

So, when you slap 'static' onto a variable inside a function, it's like saying, "Hey, keep your value, buddy, even after the function is done!" It's like that one friend who always remembers your birthday, no matter how wasted they are. And when you stick 'static' on a class member, it's like making that member part of the whole gang, you know? It's like saying, "Hey, we're all in this together, let's share the fun!"

So, yeah, 'static' in C++ is like that awesome friend who never lets you down, keeping the party going no matter what! Cheers to 'static'!






 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.