[Solved] How is argv a string array when it’s a char array?


Your code exhibits undefined behavior because you are passing a char to a functions that expects a pointer.

To print a single character you have these options,

  • fputc(argv[0][0], stdout);
  • putchar(argv[0][0]); // Effectively the same as above
  • printf("%c\n", argv[0][0]);

you can add more of printf() variants.

The reason your code crashes, is because printf(argv[0][0]); is undefined behavior since the function will try to dereference a pointer but you passed a single character and the value of such character will be interpreted as a memory address.

You really NEED to enable compiler warnings.

3

solved How is argv a string array when it’s a char array?