vendredi 26 août 2016

Trying to understand a program in C

I'm trying to understand this kind of program in C, but I can't. Exactly, I can't figure out how *s is changed, and why the compiler shows 210012.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void WhatIamDoing(char *s) {
    char ch;
    if (*s) {
        ch = *s;
        s++;
        WhatIamDoing(s);
        putchar(ch);
    }
}


int main() {
        char s[20] = "012" ;
        WhatIamDoing(s) ;
        printf( "%s", s ) ;
}

Aucun commentaire:

Enregistrer un commentaire