What is static function in cpp? Is it same as in C?

(Last Updated On: February 25, 2019)

Answer:

C++ Static function is the function that is independent of an object of the class.  And called by class name and scope resolution :: operator without creating any object.

However, there is no harm calling static functions using object, but that is redundant and may be confusing to developers in a large project as it gives impression that it is non static function in client code and considered a bad practice.

Also, static function doesn’t understand ‘this’ pointer as it is independent of objects.

C++ code example

C:

No, C++ static function is not same as in C. Static function in C is used for local linkage.