Question

In: Computer Science

Given the following variable declarations: const size_t n = 50; Write the declaration of an array...

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!)

Solutions

Expert Solution

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.


Related Solutions

Given the following processing array declaration with initialisation: int[][] foo = {{1,2,3,4,5},{2,3,4,5,6},{3,4,5,6,7},{4,5,6,7,8}}; Write a loop that...
Given the following processing array declaration with initialisation: int[][] foo = {{1,2,3,4,5},{2,3,4,5,6},{3,4,5,6,7},{4,5,6,7,8}}; Write a loop that will modify  foo so it instead contains the values {{1,4,9,16,25},{4,9,16,25,36},{9,16,25,32,49},{16,25,32,49,64}}.
Write a declaration to store the following values in an array rates : 12.9, 28.6, 11.4,...
Write a declaration to store the following values in an array rates : 12.9, 28.6, 11.4, 13.7, 9.5, 15.2, and 17.6. Include the declaration in a program that displays the values in the array by using pointer offset notation
How to print the element in the fifth row and seventh column given this array declaration...
How to print the element in the fifth row and seventh column given this array declaration in dev c: int hello[5][10];
Write a C++ program that has a function which given n>=0, create an array length n*n...
Write a C++ program that has a function which given n>=0, create an array length n*n with the following pattern, shown here for n=3 : {0, 0, 1, 0, 2, 1, 3, 2, 1} (spaces added to show the 3 groups) generateGroups(3) → [0, 0, 1, 0, 2, 1, 3, 2, 1] generateGroups(2) → [0, 1, 2, 1] generateGroups(4) → [0, 0, 0, 1, 0, 0, 2, 1, 0, 3, 2, 1, 4, 3, 2, 1]
write a function declaration for a 2d array where each row size is 8 and the...
write a function declaration for a 2d array where each row size is 8 and the function does not return anything.
Write a function declaration for a function that sums each row of a 2D array, where...
Write a function declaration for a function that sums each row of a 2D array, where each row size is 10. The function does not return a result. IN C Program.
Write a function declaration for a function that sums each row of a 2D array, where...
Write a function declaration for a function that sums each row of a 2D array, where each row size is 10. The function does not return a result. Need it in 10 minutes, please.
Given the following array, write a program in C++ to sort the array using a selection...
Given the following array, write a program in C++ to sort the array using a selection sort and display the number of scores that are less than 500 and those greater than 500. Scores[0] = 198 Scores[3] = 85 Scores[6] = 73 Scores[9] = 989 Scores[1] = 486 Scores[4] = 216 Scores[7] = 319 Scores[2] = 651 Scores[5] = 912 Scores[8] = 846
1. Given an array of integers a dimension n. If the array contains the same number...
1. Given an array of integers a dimension n. If the array contains the same number of even and odd elements get (a1 + an) (a2 + an-1) ... 2. Given an array of integers dimension n. All array elements with even numbers preceding the first element to the maximum, multiplied by the maximum. 3. Given an array of dimension n. Insert after each zero element of the element in the middle (or the amount of secondary elements for even...
Write a JAVA pogram for the following scenario. Given an n × n × n cube...
Write a JAVA pogram for the following scenario. Given an n × n × n cube containing n3 cells, we are to place n queens in the cube so that no two queens challenge each other (so that no two queens are in the same row, column, or diagonal). In JAVA, implement it on your system to solve problem instances in which n = 4 and n = 8.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT