How to use gdk_device_get_position()?

use Gdk.DeviceManager.

.....
.....
GdkDisplay *display = gdk_display_get_default ();
GdkDeviceManager *device_manager = gdk_display_get_device_manager (display);
GdkDevice *device = gdk_device_manager_get_client_pointer (device_manager);

// do whatever with Gdk.Device, i.e:
int x, y;
gdk_device_get_position (device, NULL, &x, &y);
printf ("x= %d, y=%d", x,y);

Since GTK+ 3.20+, luciomrx's answer becomes:

GdkDisplay* display = gdk_display_get_default();
GdkSeat* seat = gdk_display_get_default_seat(display);
GdkDevice* pointer = gdk_seat_get_pointer(seat);