Conversion C to C++

Asked

Viewed 86 times

0

Guys, does anyone know what this code means in c++?

#include <iostream>

#define MAX_C (10)
using namespace std;

int compar(const void *x, const void *y) {
    int a = *((int *) x);
    int b = *((int *) y);
    return a - b;
}
  • this method returns the difference of two values within pointers.

  • 2

    I was a little confused, where enters the "Conversion C to C++" of the title in doubt?

  • I believe it is because this code has all the face of C; in C++ could do using templates..

  • This code is already C with the exception of Std.

1 answer

0

Good Morning,

Analyzing the code, the big difference is the use of Library Iostream, which in this code, frankly, is not valid. For at no time is anything called from this library.

This #define is also not being used in this code. And if the goal is to have a constant, use const int = MAX_C 10;

As for the function, it returns the difference between two pointers. In which a cast is cast for int.

It would be more cool to use a Template, since we are talking about C++.

Hugs

  • const that’s not quite it. constexpr would be appropriate.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.