consider the statement
++*p++
if it is valid then evaluate it.

Hello,

I am no C++ genius, but

++*p++

Cannot be a statement by itself, as there is no ; to finish it.

I am trying to remember if *p is significant. I know that &p is... the address of the variable p. p++ is just an incrementor. But C++ has been a "variable first, then operator" type of language. cars++ people--

I think it is an error.

Christian

Increment the object pointed to by p, then increment the pointer p (point to the next object).

#include <stdio.h>
  
  int main(void)
  {
     char text[] = "1b#", *p = text;
     printf("text = \"%s\", p(%p) = \"%s\", *p = '%c'\n", text, (void*)p, p, *p);
     ++*p++;
     printf("text = \"%s\", p(%p) = \"%s\", *p = '%c'\n", text, (void*)p, p, *p);
     return 0;
  }
  
  /* my output
  text = "1b#", p(0012FF88) = "1b#", *p = '1'
  text = "2b#", p(0012FF89) = "b#", *p = 'b'
  */

Really, this code is trivial to come up with on your own. At least give these a try.

Hello,

I stand corrected. Reading another post in the forum, people apparently do use ++variable syntax. I always took the style of variable++ and went with it to avoid confusion.

So

++p would be valid.

++*p++ I think is a problem.

Christian

You could say its valid, though it really all depends on how or why its used:

void pointTo(char **src, char *dst) {
	*src = dst;
}

int main() {
	char h[25];
	char *hello;

	pointTo(&hello, h);

	strcpy(h, "Hello world!");

	printf("%c\n", [b]++*hello++[/b]);

	return 0;
}

You could ask yourself, "Wow, how'd it come up with 'I'?", though its perfectly understandable. *hello++ is 'H', as the first letter of our string, though ++*hello++ moves our first letter 'H' one to the right, resulting in the next letter of the alphabet, 'I'.


Hope this makes sense,
- Stack Overflow

hello, well this is valid in C++ but you may try to do it in separate statements or store the results in separate pointers just to avoid the logical errors that might occur, always remember flexibility comes before simplisity ;)

Yeah,it is hard to konw.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.