How can I find out in Win64 how many processor cores there are in the system?

Andrey Karpov
Articles: 565

To get information about the number of processor cores in the system, you may use the Windows environment variable NUMBER_OF_PROCESSORS. Below is a fragment of C++ code where the WinAPI GetEnvironmentVariable method is used to extract and display the contents of this environment variable.

#include <windows.h>
#include <tchar.h>
#include <stdio.h>

#define BUFSIZE 4096

int main()
  DWORD dwRet = GetEnvironmentVariable(VARNAME, buf, BUFSIZE);
  if (dwRet > 0 && dwRet < BUFSIZE)
    _tprintf(_T("Number of processors: %s\n"), buf);

  return 0;


Use PVS-Studio to search for bugs in C, C++, C# and Java

We offer you to check your project code with PVS-Studio. Just one bug found in the project will show you the benefits of the static code analysis methodology better than a dozen of the articles.

goto PVS-Studio;

Andrey Karpov
Articles: 565

Bugs Found

Checked Projects
Collected Errors
14 526
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site. Learn More →