0
#inlcude <stdio.h>
#inlcude <stdlib.h>

int main (int argc, char* argv[])
{

     if (argc != 3)
     {
          return 1;
     }

     char* inf = argv[1];
     char* outf = argv[2];

The char* argv[] is a pointer pointing to the command line argument strings. When the strings are assigned to new char pointers, what does inf and outf hold. Do they hold the addresses of the strings indexed at argv[1] and argv[2] or the actual values.

If they hold the addresses, aren't they pointing to other pointers; don't they require double asterisks.

Can a pointer variable hold a value or they are meant to hold addresses only?

1
  • argv[1] and argv[2] isn't assigned inf and outf, rather inf and outf is assigned to them. inf and outf both hold pointers to the first char in the string literal they point to, and when printed everything up until the next \0 will be printed.

  • Since inf and outf becomes assigned to argv [1] and [2] respectively, and it these two who are the pointers in question, double asterisks are not required and would result in an error.

In both cases, they point to a string literal, so when printed they will print everything up until the next \0, that is the entire string that was input by the user. String literals, if you're not sure, are simply a pointer that points to the first char in a continuous block of memory no larger than the text it holds.

  • Pointer variables can only contain an address to a location in memory, though they can also contain another pointer.

If this answers your question please accept the answer by clicking the check mark to remove this question from the unanswered pool, otherwise feel free to leave a comment ;)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .