Skip to content

Instantly share code, notes, and snippets.

@vasalf
Created October 12, 2019 17:07
Show Gist options
  • Save vasalf/6e59efe0bee4daa2839d08d1d2ae43b7 to your computer and use it in GitHub Desktop.
Save vasalf/6e59efe0bee4daa2839d08d1d2ae43b7 to your computer and use it in GitHub Desktop.
Практика 5': Упражнения на указатели
void task1() {
int x = 179;
int* p = &x;
int** n = malloc(sizeof(int*));
}
/*
Какой тип у выражений?
1. p
2. *p
3. &p
4. *n
5. **n
6. &n
7. &(&n)
*/
void task2() {
int x[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
}
/*
Чему равно выражение?
1. *x
2. *(x + 5)
3. &x[0] - x
4. &x[4] - x
5. (void*)(&x[4]) - (void*)x
6. (void*)(&x[100]) - (void*)(&x[99])
*/
struct point {
int x, y;
} __attribute__((packed));
void task3() {
struct point p;
struct point* ptr = &p;
}
/*
Какой тип у выражений?
1. p
2. p.x
3. &p
4. *p
5. ptr
6. &ptr
7. ptr->x
8. &p.x
9. &ptr->x
*/
struct foo {
int x;
char c;
struct point p, q;
int a[19];
short w;
struct point r[10];
} __attribute__((packed));
void task4() {
struct foo f;
}
/*
Чему равно выражение?
1. sizeof(struct foo)
2. sizeof(f.x)
3. (void*)(&f.x) - (void*)(&f)
4. (void*)(&f.c) - (void*)(&f)
5. (void*)(&f.a) - (void*)(&f)
6. (void*)(&f.a[10]) - (void*)(&f)
7. (void*)(&f.p.x) - (void*)(&f.x)
8. (void*)(&f.r[3].x) - (void*)(&f)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment