Incrementing array of pointers as a formal argument compiled and executed

Viewed 25

As we can't increment base address of an array, the following code won't compile.

int main(void)
{
    /* Array of pointers initialization */
    char *argv[] = {"hello", "world"};

    puts(*++argv);  // Gives compile time error
    return 0;
}

But I am unable to figure out why the following code compiled and executed successfully. The formal argument of func(char *argv[]) is also an array of pointers right?

#include <stdio.h>

void func(char *argv[])
{
    puts(*++argv);  //Compiles fine
}

int main(void)
{
    char *argv[] = {"hello", "world"};

    func(argv);
    return 0;
}

Anybody please explain the mechanism behind it.

0 Answers
Related