1# C++ CODE
2void divide_modulo(int a, int b, int *div, int *rest)
3{
4 *div = a / b;
5 *rest = a % b;
6}
7
8# COMPILE WITH
9gcc -o libexample.so -shared example.c
10# OR C++
11g++ -o libfoo.so -shared example.cpp
12
13# PYTHON 3.7 CODE
14import ctypes
15lib = ctypes.cdll.LoadLibrary('./libexample.so')
16
17def divide_modulo(a, b):
18 div = ctypes.c_int(0)
19 rest = ctypes.c_int(0)
20 lib.divide_modulo(a, b, ctypes.byref(div), ctypes.byref(rest))
21 return (div.value, rest.value)
22
23print(divide_modulo(11, 4))