A
A
Alexander2020-06-28 09:33:22
C++ / C#
Alexander, 2020-06-28 09:33:22

What do the expressions *++argv and (*++argv)[0] mean?

There are some command line arguments.
And there is an expression *++argv. it is written that this is a pointer to a string argument.
And (*++argv)[0] is the first character and is equivalent to **++argv.

Please explain the logic of these expressions.
And a couple of questions.
1. *++argv why is it a pointer? If * means dereference.
2. (*++argv) [0] - why is ++ here, if you don't add a lot, [0] will point to the first element, that is, to the program name itself.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2020-06-28
@Shemapp

argv is a pointer of a specific type.
++ - Pre-increment operator, for pointers it increases by the size of the pointer type.
* - dereference operator. Getting the value from memory where the pointer is pointing.
[0] - operator for getting value by index, for arrays.
You get a pointer to an array of command line values, the values ​​are strings.
++argv - points to the beginning of the second value from the command line.
and [0] on the first character of that value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question