compilation - Different IDEs, Different results with postfix++ on c++ -


this question has answer here:

there. found interesting problem.

i ran below code on different ides, clion , ideone.

printf("ptr : %x, *ptr : %c\n", ptr, *ptr++); 

and surprisingly got different results both.

and below full source codes.

int main(){     char buf[6] = {'a', 'b', 'c'};     char* ptr = buf;      int = 0;      for( = 0 ; < 6 ; i++ ){         printf("ptr : %x, *ptr : %c\n", ptr, *ptr);         ptr++;     }      printf("ptr points buf\n");     ptr = buf;     printf("buf : %x %x \n", buf, ptr);     printf("*ptr++ : \n");     printf("ptr : %x, *ptr : %c\n", ptr, *ptr++);     printf("*(ptr++) : \n");     printf("ptr : %x, *ptr : %c\n", ptr, *( ptr++ ));      return 0; } 

below result clion

ptr : 568caa96, *ptr : ptr : 568caa97, *ptr : b ptr : 568caa98, *ptr : c  ptr points buf *ptr++ : ptr : 568caa96, *ptr : *(ptr++) : ptr : 568caa97, *ptr : b 

below result ideone.

ptr : ede24d40, *ptr : ptr : ede24d41, *ptr : b ptr : ede24d42, *ptr : c  ptr points buf *ptr++ : ptr : ede24d41, *ptr : *(ptr++) : ptr : ede24d42, *ptr : b 

actually hadn't expected result ideone. , doubt they've got different compiler , that's reason why showing different results.

am alright? if so, i'd know how comes , how compilers work on printf sentence.

thanks lot.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -