-1

     int main(void)
        {
            int e;
            char *envp[] = {NULL};
            char *argv[] = {"/bin/ls", "-1",NULL};
            //char *argv[] = {"/bin/ls", "-1",NULL};
            argv[1]= "0";;
            //e =  execve("/bin/ls", argv, envp);
            return 0;
}

I have used this code but according to the declaration of execve it takes second parameter as const pointer to char but i have passed without const yet it is working fine. why????

akshay
  • 1

1 Answers1

0

In C, you can always pass a char* to a function that accepts const char* which is a compatible/legal assignment. You could of course pass const char* argument which is fine, too. But generally, the const qualifier in the first argument of execve simply says that the function execve wouldn't modify it.

Also see this related post: Why can't I pass a char ** to a function which expects a const char **?

P.P
  • 117,907
  • 20
  • 175
  • 238