Programming in C:
1. Given the following variable declarations:
const size_t n = 50;
2. Write the declaration of an an array of pointers to n memory blocks containing 16-bit signed integer values. Use 'x' for the name of the variable.
3. What is the type of the variable x?
uint8_t *x[256];
4. What type does the variable x decay to when used in an expression?
uint8_t *x[256]
5. What is the data type of an array of five strings?
6. Write the declaration of an array of 128 strings. Use 's' for the name of the variable.
SOLUTION:
1.) const size_t n=50;
signed __int16 *x[n];/*an array of pointers since dereference pointer(*) have lower precedence then subscript operator([])*/
/*16 bit integers and by default signed integers we could have written short, short int or signed short int which have the same data type declarations*/
3) uint8_t *x[256];
Here, x is a pointer variable of datatype unsigned char because, 8 bit integer is equivalent to a char byte.
4) uint8_t *x[256]
Here, 'x' is a pointer variable of datatype unsigned char but the values stored by 'x' will be the address of character pointers which is compiler dependent.
Using it as *x[index] will give us a character.
5) The data type of 5 strings will be character. Char pointers will be used for storing 5 strings.
6) The declaration of an array of 128 strings.
char *s[128];
Get Answers For Free
Most questions answered within 1 hours.