What is the difference between internal and external linkage (the static and extern keywords)?

Last updated 21 June 2026

  • External linkage makes a name visible program-wide via the linker (default for non-const globals and free functions). extern declares it without defining it.

  • Internal linkage keeps a name private to its translation unit: namespace-scope static, unnamed namespaces, and const/constexpr globals by default. This prevents link-time clashes.

  • Prefer unnamed namespaces over file-scope static, and C++17 inline variables for shared globals defined in headers.

  • https://www.geeksforgeeks.org/c/internal-linkage-external-linkage-c/
  • https://www.geeksforgeeks.org/c/storage-classes-in-c/
  • https://medium.com/@tkxa7064/c-linkage-internal-vs-external-understanding-type-relationships-e8788b875403
  • https://www.geeksforgeeks.org/c/understanding-extern-keyword-in-c/
All C++ interview questions