What is a static member function in C?
C has no member functions, but a static function is private to its source file. Learn internal linkage and how it differs from C++ static members.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
C has no member functions, but a static function is private to its source file. Learn internal linkage and how it differs from C++ static members.
An inline function in C is a hint to substitute the body at the call site. Learn the C99 linkage rules, static inline, and when macros are worse.
C has no reference variables; pointers do the same job. See how to pass by pointer, how pointers differ from C++ references, and how to use them safely.
Standard C has no smart pointers, but you can get similar safety with ownership rules, cleanup labels, the cleanup attribute and reference counting.
C has no move constructors, but you can transfer ownership of a struct by hand. See the pattern, a runnable example and safe habits.
C has no conversion constructors, only built-in implicit conversions and explicit casts. Learn the rules and how to write conversion functions for your own types.
Copy constructors are a C++ feature, so C has none. See how struct assignment behaves and how to write your own safe copy function in C.
C has no constructors, so structs are not initialised for you. Learn the zero initialiser, init functions and default macros that replace a default constructor.
Templates are a C++ feature. Here is how to get generic behaviour in C using macros, _Generic from C11, and void pointers, with the trade-offs.
C has no class templates, but you can generate typed structs with macros and dispatch by type with _Generic. See the techniques and trade-offs.
The stack is fast and automatic, while the heap is flexible and manually managed with malloc and free. Learn lifetimes, common bugs and when to use each.
C is a small procedural language, while C++ adds classes, templates, RAII and a large standard library. See the differences with code and a comparison table.
C has no new operator, so you allocate with malloc, calloc and realloc and release with free. Here is how that differs from C++ new.
The this pointer is a C++ feature. In C you pass the struct pointer yourself, and function pointers or vtables give you method-style calls and polymorphism.
C has no pure virtual functions, but you can emulate abstract interfaces with a const table of function pointers. Includes a full runnable C example.
C has no virtual keyword. This answer shows how a struct holding a table of function pointers gives you the same run-time dispatch.
A shallow copy in C duplicates pointer values, a deep copy duplicates the data they point to. See examples, pitfalls like double free and a safe pattern.
C does not support friend functions. This guide explains why and shows how opaque pointers and private headers achieve the same goal.
In C, an object is any storage that holds a value, and an instance is a variable of a struct type. See how structs and functions emulate object-style code.
C has no namespace keyword, so name conflicts are avoided with prefixes, static linkage, headers and hidden symbols. See how each technique works.