[Solved] Parameter passing in C [closed]


As you can see from the declaration, argv is an array of char pointers. This means that your main function is not being passed the numerical value 5, but the (probably ASCII- or UTF8-) encoded string value “5”. If you look at ASCII table, you will see that the character “5” is encoded as the numerical value 53 in ASCII. You can also see that the letter “a” is encoded as number 97, so running ./myProgram a should output Parameter = 97.

To get the numerical value of an ASCII-encoded string you can use atoi(), e.g. write

int main(int argc, char *argv[]) {
    int param = atoi(argv[1]);
    printf("Parameter = %d\n",param);   
}

4

solved Parameter passing in C [closed]