In SWIG , how can i use int * variable without typemaps.i
Question: I have a program where in a C function somewhat like below code. When i try to
call this function via python it it throwing error saying

argument 2 of type 'int *'. In swig i saw there is way to handle this that is
via typemaps is there any other way other typemaps. As there are bunch of
functions with numerous arguments having int * .

    
    
    #include<stdio.h>
    
    int check(int k, int *i) {
      if( k%2 == 0) 
        *i = 1;
      else 
        *i = 0;
    } 
    


Answer: Typemaps are really the way SWIG handles all types, but if you don't want
`typemaps.i` specifically, then how about:

    
    
    %module x
    
    %include <cpointer.i>
    %pointer_functions(int,int)
    
    %inline %{
    
    void check(int k, int *i) {
      if (k % 2 == 0) 
        *i = 1;
      else 
        *i = 0;
    }
    
    %}
    

`cpointer.i` lets you create simple pointers to a type. Here's an example of
use:

    
    
    >>> import x
    >>> i=x.new_int()
    >>> x.check(6,i)
    >>> x.int_value(i)
    1
    >>> x.delete_int(i)
    

But really, it is simpler to use `typemaps.i`. Below `%apply` applies the
predefined `OUTPUT` typemap, declaring that all future `int *` parameters are
output parameters. Python will not require the parameter for the call, and
will return the parameter as an output instead. The normal return value and
all output parameters are returned using a tuple if necessary.

    
    
    %module x
    
    %include <typemaps.i>
    %apply int *OUTPUT { int * };
    
    %inline %{
    
    void check(int k, int *i) {
      if (k % 2 == 0) 
        *i = 1;
      else 
        *i = 0;
    }
    
    %}
    

Use example:

    
    
    >>> import x
    >>> x.check(5)
    0
    >>> x.check(6)
    1
    

