-4

How can I access char from strings inside array of strings in index 1, but with pointer way I mean this way *(abc + i) for e.g:

int main(int argc, char** argv)// argc =2, argv = file name and "abcd"
{
printf("%c",____)//<--- here i want b from argv
...
}
ariel20
  • 15
  • 10

1 Answers1

1
int main(int argc, char** argv)
{
    printf("%c", *(*(argv + 1) + 1));
}

*(argv + 1) Adds 1 to argv and dereferences it to get a pointer to the second string, then one is added to that pointer to point to the second character inside that string and it is dereferenced again to get the actual char.

Don't use it in real code tough, its very unclear. use

printf("%c", argv[1][1]);
Unimportant
  • 2,076
  • 14
  • 19