Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

return a tuple c++ python 3

# C++ CODE
void divide_modulo(int a, int b, int *div, int *rest)
{
    *div  = a / b;
    *rest = a % b;
}

# COMPILE WITH
gcc -o libexample.so -shared example.c
# OR C++
g++ -o libfoo.so -shared example.cpp

# PYTHON 3.7 CODE
import ctypes
lib = ctypes.cdll.LoadLibrary('./libexample.so')

def divide_modulo(a, b):
  div = ctypes.c_int(0)
  rest = ctypes.c_int(0)
  lib.divide_modulo(a, b, ctypes.byref(div), ctypes.byref(rest))
  return (div.value, rest.value)

print(divide_modulo(11, 4))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #return #tuple #python
ADD COMMENT
Topic
Name
7+7 =