What is pointer to string in C?

argv is an array of pointers pointing to zero terminated c-strings.

I painted the following pretty picture to help you visualize something about the pointers.

enter image description here

And here is a code example that shows you how an operating system would pass arguments to your executable. You can call your executable via command line and add any number of additional arguments separated with spaces.

#include <stdio.h>

int mainLookalike(int argc, char * argv[])
    for (int i = 0; i < argc; ++i)
        switch (i)
            case 0: printf("application name is: %s\n", argv[i]); break;
            default:  printf("argument %i is: %s\n", i, argv[i]); break;
    return 0;

int main(int argc, char * argv[])
    printf("arguments taken from main\n");
    mainLookalike(argc, argv);
    printf("created my own arguments\n");
    char * app = "MyApplication.exe";
    char arg1[] = "argonaut";
    char * arg2 = "widgeteer";

    char * myargv[] = {app, arg1, arg2};
    int myargc = sizeof(myargv) / sizeof(char*);
    mainLookalike(myargc, myargv);
    return 0;

Browse More Popular Posts

Leave a Comment