Question: I usually code in C++, but I'm working on a project in C and I came across a printf with the following syntax: 

```
printf( 0, "%d\n", num);

```

I've looked around and can't find an explanation of what the first 0 in the printf does. Can someone please explain it to me? Thanks.

Answer: 
Because [xv6](https://github.com/Travis-Xiao/xv6-reform/blob/master/printf.c) is not using `printf` from the standard library:

```
void
printf(int fd, char *fmt, ...)
{
    char *s;
    int c, i, state;
    uint *ap;
    state = 0;
    ap = (uint*)(void*)&fmt + 1;
    for(i = 0; fmt[i]; i++){
        c = fmt[i] & 0xff;
        if(state == 0){
            if(c == '%'){
                state = '%';
            } else {
                putc(fd, c);
            }
        } else if(state == '%'){
            if(c == 'd'){
                printint(fd, *ap, 10, 1);
                ap++;
            } else if(c == 'x' || c == 'p'){
                printint(fd, *ap, 16, 0);
                ap++;
            } else if(c == 's'){
                s = (char*)*ap;
                ap++;
                if(s == 0)
                    s = "(null)";
                while(*s != 0){
                    putc(fd, *s);
                    s++;
                }
            } else if(c == 'c'){
                putc(fd, *ap);
                ap++;
            } else if(c == '%'){
                putc(fd, c);
            } else {
            // Unknown % sequence. Print it to draw attention.
                putc(fd, '%');
                putc(fd, c);
            }
            state = 0;
        }
    }
}

```
```
printf( 0, "%d\n", num);

```

invokes undefined behavior because the first argument of `printf` has to be a pointer to a string.