from ctypes import c_void_p, cast


def c_ptr_add(ptr, other):
    """
    Add an integer to a pointer instance.
    Returns a new pointer:

    >>> import ctypes
    >>> string_ptr = ctypes.c_char_p(b'foobar')
    >>> string_ptr.value
    b'foobar'
    >>> p2 = c_ptr_add(string_ptr, 3)
    >>> print(p2.value)
    b'bar'
    >>> string_ptr.value
    b'foobar'
    >>>
    """
    try:
        offset = other.__index__()
    except AttributeError:
        raise TypeError("Can only add integer to pointer")
    void_p = cast(ptr, c_void_p)
    void_p.value += offset #* sizeof(ptr._type_)
    return cast(void_p, type(ptr))