- 2074 Chaitra · 5 marks
Interpret pointer declarations
Short answer
i) p is a pointer to int. ii) p is a function taking char* returning int. iii) p is a function taking char* returning int*. iv) p is a function taking void returning int*. v) p is an array of 10 pointers to functions taking char returning int*.
Define following term: i) intp; ii) int p(chara) iii) int(p(chara)) iv) int p(void) v) int(*p[10])char a)
(The last declaration is written as int *(*p[10])(char a), assuming the missing brackets.)
| Declaration | Meaning |
|---|---|
i) int *p; | p is a pointer to an integer |
ii) int p(char *a) | p is a function taking a pointer to char and returning an int |
iii) int (*p(char *a)) | The brackets are redundant: same as int *p(char *a). p is a function taking a pointer to char and returning a pointer to int |
iv) int *p(void) | p is a function with no arguments returning a pointer to int |
v) int *(*p[10])(char a) | p is an array of 10 pointers to functions, each taking a char and returning a pointer to int |
How to read: start at the name, go right ([] or ()), then left (*), and use brackets to change the order. For (v): p[10] is an array of 10, * makes them pointers, (char a) makes them pointers to functions, and int * is the return type.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Series 1×10+3×20+6×30+… · Computer Programming, chapter 5
- Correct program: character arrays · Computer Programming, chapter 7
- Correct program: do-while and pow · Computer Programming, chapter 3
- Correct program: Celsius to Fahrenheit · Computer Programming, chapter 3
- Correct program: case array and average · Computer Programming, chapter 3
- Sensitivity in 10% steps; interpret · Engineering Economics, chapter 6
- Sensitivity on investment, revenue and life; interpret · Engineering Economics, chapter 6
- RMR class IV support and excavation · Engineering Geology II, chapter 6 · asked 6×
- Internal discharge in disc with 0.01 mm void · High Voltage Engineering, chapter 6 · asked 3×