How to Get the Number of Processors in a Windows System using C? Multi-core processors are ubiquitous in the world of computing today, and systems with multiple processors are common. To optimize your code or allocate resources, a coder may need to know the system’s processor count.
Here is an example program that demonstrates how to determine how many processors are present in a Windows system:
#include <stdio.h>
#include <windows.h>
int main() {
SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo);
DWORD numProcessors = systemInfo.dwNumberOfProcessors;
printf("Number of processors: %lu\n", numProcessors);
return 0;
}
I do sincerely hope you find this informative, and use it in your programs. If you wish to learn more about C, please subscribe to our newsletter today and continue your C learning journey with us!