[ create a new paste ] login | about

Link: http://codepad.org/FxstodmY    [ raw code | output | fork ]

C, pasted on Sep 16:
#include <stdio.h>
#include <stdarg.h>

char *first(int nargs, ...)
{
    va_list ap;
    char *r = NULL;

    va_start(ap, nargs);
    for( ; nargs; nargs--) {
        r = va_arg(ap, char*);
        if (r != NULL) break;
    }
    va_end(ap);

    return r;
}

int main(void) {
    
    char *q = NULL;
    char *w = NULL;
    char *e = "zzz";
    char *r = NULL;

    char *ret = first(4, e, q, w, r);

    printf("result: %d", ret == e);

    return 0;
}


Output:
1
result: 1


Create a new paste based on this one


Comments: