c++ - Hexadecimal doubts and C + + -


my question is: why there "--p", understand "++p"function serves climb number of imaginary array pointer, "--p" that? realized without code letters not shown did not understand how works. , more

code :

#include <stdio.h>  using namespace std;  int main() {     char* p = new char [12];     *p=0x48;     ++p;     *p=0x65;     ++p;     *p=0x6c;     ++p;     *p=0x6c;     ++p;     *p=0x6f;     ++p;     *p=0x20;     ++p;     *p=0x57;     ++p;     *p=0x6f;     ++p;     *p=0x72;     ++p;     *p=0x6c;     ++p;     *p=0x64;     ++p;     *p=0x0;     ++p;      --p;     --p;     --p;     --p;     --p;     --p;     --p;     --p;     --p;     --p;     --p;     --p;      printf(p);     delete p;      return 0 ;  } 

char *p = _ _ _ _ _ _ _ _ _ _ _ _          /\ 

initially p points beginning of array shown

p++ == ++p == (p = p+1)  

so moves pointer forward 1 place right.

p-- == --p == (p = p-1)  

so moves pointer back 1 place left.


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -