연산자 우선순위와 결합순서

연산순위연산자결합순서
1() [] -> .→
2! ~ ++ -- + - (type) * & sizeof←
3* / %→
4+ -→
5<< >>→
6< <= > >=→
7== !=→
8&→
9^→
10|→
11&&→
12||→
13? :←
14= += -= *= /= %= &= ^= |= <<= >>=←
15,→

Doubld Pointer

int i = 1000;
int *p =&i;
int **pp = &p;

0x20000x30000x4000
1000i0x2000p0x3000pp
i → 1000p → 0x2000pp → 0x3000
&i → 0x2000&p → 0x3000&pp → 0x4000
*p → 1000*pp → 0x2000
**pp → 1000

Dynamic Allocation in C

void main(int argc, char *argv[])
{
 int i;
 char **pp;
 pp = malloc(5 * sizeof(char*));
 if(!pp){perror("Insufficient memory available\n"); return;}
 for(i = 0; i < 5; i++)
 {
  pp[i] = malloc(9);
  if(!pp[i]){perror("Insufficient memory available\n"); return;}
 }
 // ...
 for(i = 0; i < 5; i++)free(pp[i]);
 free(pp);
}

Dynamic Allocation in C++

void main(int argc, char *argv[])
{
 int i;
 char **pp;
 pp = new char*[5];
 for(i = 0; i < 5; i++)pp[i] = new char[9];
 // ...
 for(i = 0; i < 5; i++)delete[]pp[i];
 delete[]pp;
}