In: Computer Science
Given the following variable declarations: const size_t n = 50; Write the declaration of an array of pointers to n memory blocks containing 16-bit signed integer values. Use 'x' for the name of the variable. (Don't forget the semi-colon at the end of the declaration!)
It is very simple, see first let us learn what is an array of pointers?
An array of pointers is simply an array containing pointers to some memory block of some specific datatype, here the datatype is 16-bit signed integer values.
So, declare a 16-bit integer, we use this notation 'int16_t', example -
#include<stdint.h>
int16_t some_variable_name;
BUT REMEMBER THAT TO USE IT YOU NEED TO USE '#INCLUDE<STDINT.H>' AS A LIBRARY FILE, OTHERWISE IT WILL NOT WORK.
So, to declare an array, we will use this type of keyword -
// This is not an array of pointers, rather an array of integers, you will find it below.
// It is just an example.
int16_t array_name[size_of_the_array];
In the 'size_of_the_array', we will give an integer value of our choice, here we will give 'n', as you told, but make sure to declare 'n' with an integer value.
In the position of 'array_name', we will give our variable name 'x', please see below.
Please note that to make an array of pointers of 16-bit integer data type, we use this - ('*' is the sign of pointer, and 'int *x' means that pointer of integer data type)
#include<stdio.h>
#include<stdint.h>
int main(){
int n = 10;
// An array of pointers of 16-bit integer data type, with size n.
// your answer...
int16_t *x[n];
return 0;
}
To get the 'n' number of memory blocks, just change the number 'n' in the program to your choice, and you are good to go.
Also, the semi-colon is there. :)
Hope you have learned a lot, and now can do this.
If you find my answer helpful, then please do upvote this, and Happy Learning. Thank you.