Jagan Jagan - 3 years ago 59
C Question

Why can't we declare a static variable within a structure in the C programming language?

Why can't we declare a static variable within a structure in the C programming language?

Answer Source

In C++, a struct is basically a class with all members public, so a static variable makes good sense there.

In C, a struct is a contiguous chunk of memory with fields. A static variable can not be created without changing that (as to implement a static you need to refer to a single memory location from all structs of that type), and that would be a big difference in complexity without much benefit.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download