Monday, March 31, 2008

Every keyCode is 229?!

I need to blog this. When I was debugging javascript, I found that no matter I press "A" or "X", the keyCode of it is 229. It turned out that I was typing using Microsoft PinYin. Although the mode is English instead of Chinese, it is Chinese input keyboard anyway. That's why the keyCode behaves strangly.

Sunday, March 2, 2008

Constant Pointers and Pointers to Constants

1. Pointer to Constant
char char_A = 'A';
const char * myPtr = &char_A;
*myPtr = 'J'; // error - can't change value of *myPtr

2. Constant Pointer
char char_A = 'A';
char char_B = 'B';

char * const myPtr = &char_A;
myPtr = &char_B; // error - can't change address of myPtr

Difference between Reference and Pointer

Difference between Reference and Pointer in C++

  1. Reference should be initialized and pointer need not be.

  2. Reference can’t point to NULL and pointer can.

  3. Reference can’t be changed to some other objects it is once initialized but pointer can be.

  4. Pointer can be incremented or decremented and subjected to any pointer arithmetic operations, but reference can’t.