Let\'s consider the following hello world examples in C and C++:
main.c
#include
int main()
{
printf(\"Hello world\\n\");
r
You are not comparing C and C++. You are comparing printf and std::cout, which are capable of different things (locales, stateful formatting, etc).
Try to use the following code for comparison. Godbolt generates the same assembly for both files (tested with gcc 8.2, -O3).
main.c:
#include
int main()
{
int arr[6] = {1, 2, 3, 4, 5, 6};
for (int i = 0; i < 6; ++i)
{
printf("%d\n", arr[i]);
}
return 0;
}
main.cpp:
#include
#include
int main()
{
std::array arr {1, 2, 3, 4, 5, 6};
for (auto x : arr)
{
std::printf("%d\n", x);
}
}