Question

In: Computer Science

Consider the following declaration: typedef struct{                                  &nbsp

Consider the following declaration:

typedef struct{
                                         int A;
                                         char B[10];
                                         float C;
                                         char D;

                                 }rectype;
                                  typedef rectype matrix[121][4][5];
                                  matrix A1;

Compute the address of element A1[120][3][3] given the base address at 2000.

Solutions

Expert Solution

Solution:

step1: The basics are

To determine the ith element of a Three-dimension array:A[i][j][k]=BA+[(i)*(UB2)*(UB3)+(j)*(UB3)+(k)]* datasize

Where

UB3–upper bound of the 3rd dimension

UB2–upper bound of the 2nddimension

BA is base or starting address

datasize–element size in bytes

Step2:

But if we see the size of rectype is 24 bytes because of sizeof(structure) is arranged in the form of words for processor. For a 32 bit processor it is 4bytes each word and for 64 bit processor it is 8bytes each word.

int size=4 bytes, char size=1 byte, float size=4 bytes

Hence size(rectype)=firstword for integer+second,third,fourth for char B+fifth for float + sixth for char

=

1 2 3 4 5 6

int A char B char B char B float C char D

=first word is occupied by integer+second is occupied by 4 char+third is occupied by 4 char+fourth is occupied by 2 char(remaining 2 bytes goes in fragmentation)+fifth word by float+sixth by char (remaining 3 bytes is wasted)

=4+4+4+4+4+4=24 bytes

i=120, j=k=3 UB2=4 UB3=5 BA=2000 datasize=24 bytes

A1[120][3][3]=BA+[(i)*(UB2)*(UB3)+(j)*(UB3)+(k)]* datasize

=2000+[120*4*5+3*5+3]*24=60032

conclusion: Hence the address of element A1[120][3][3] if the base address 2000 is 60032.


Related Solutions

#include<stdlib.h> #include<stdio.h> typedef struct node {    void* dataPtr;    struct node* next; } QUEUE_NODE; typedef...
#include<stdlib.h> #include<stdio.h> typedef struct node {    void* dataPtr;    struct node* next; } QUEUE_NODE; typedef struct {    QUEUE_NODE* front;    QUEUE_NODE* rear;    int count; } QUEUE; //Prototype Declarations QUEUE* createQueue(void); QUEUE* destroyQueue(QUEUE* queue); bool dequeue(QUEUE* queue, void** itemPtr); bool enqueue(QUEUE* queue, void* itemPtr); bool queueFront(QUEUE* queue, void** itemPtr); bool queueRear(QUEUE* queue, void** itemPtr); int queueCount(QUEUE* queue); bool emptyQueue(QUEUE* queue); bool fullQueue(QUEUE* queue); /*================= createQueue ================ Allocates memory for a queue head node from dynamic memory and returns...
Using the following definitions for a binary tree, typedef struct bintreenode {     int data;     struct bintreenode*...
Using the following definitions for a binary tree, typedef struct bintreenode {     int data;     struct bintreenode* left;     struct bintreenode* right; } btreenode; // Used for a node in the queue. typedef struct node {     btreenode* nodePtr;     struct node* next; } node; // Used to represent the queue efficiently. typedef struct queue {     node* front;     node* back; } queue; Implement the following functions: void bfs(btreenode* root) // Prints a breadth first search traversal of the binary search tree rooted at root....
declare a struct named matrix and typedef the struct to type name Matrix. A mathematical matrix...
declare a struct named matrix and typedef the struct to type name Matrix. A mathematical matrix is a two-dimensional, rectangular data structure. The matrix struct should have three fields (in this order): an unsigned variable named "rows", an unsigned variable named "columns", and a pointer to a pointer to double (i.e. double**) named "data". (Code #including matrix.h should be able to declare Matrix variables.) In matrix.c, implement the create_matrix function. The Matrix should be filled with 0.0 values. data[i] should...
#include <stdio.h> typedef struct Coordinates { int x; int y; } Coordinate; typedef union uCoordinates {...
#include <stdio.h> typedef struct Coordinates { int x; int y; } Coordinate; typedef union uCoordinates { int x; int y; } uCoordinate; // TODO - Populate 4 different Coordinates with any numbers between 1 and 99 for x & y values // using coordinate1, coordinate2, coordinate3, & coordinate4 as Coordinate names // TODO - Print to screen the x & y values of each coordinate // TODO - Replace the following with your name: Ethin Svoboda int main() { //...
Create a typedef fruitType using the struct fruitType_struct to store the following data about a fruit:...
Create a typedef fruitType using the struct fruitType_struct to store the following data about a fruit: name (string, up to 50 characters long) color (string, up to 10 characters long) fat (integer) sugar (integer) carbohydrate (integer) Write a void function called printFruit that takes a fruitType parameter and prints the data (as shown in the example below). Declare a variable of type fruitType to store the following data: name: banana color: yellow fat: 1 sugar: 15 carbohydrate: 22 then use...
#include<stdio.h> #include<stdlib.h> struct listNode{ int data; struct listNode *nextptr; }; typedef struct listNode node; void insert(node*);...
#include<stdio.h> #include<stdlib.h> struct listNode{ int data; struct listNode *nextptr; }; typedef struct listNode node; void insert(node*); void showList(node*); void printListBackwards(node *); int main(void) { node *list1; printf("\n Create a sorted list.."); printf("\n Enter values for the first list (-999 to end):"); list1=(node*)malloc(sizeof(node*)); //Allocate memory for the list node insert(list1); //insert values by calling the function insert showList(list1); //display values entered by user printf("\n After recursively reversing the list is :\n"); printListBackwards(list1); //print the values in reverse order using the function...
I have the following code #include <stdio.h> #include<string.h> #define BUFLEN 128 typedef struct { int numPhrases;...
I have the following code #include <stdio.h> #include<string.h> #define BUFLEN 128 typedef struct { int numPhrases; }SyncInfo; char buffer[BUFLEN] ; char *phrases[] = {"educated", "educated cat", "educated lion", "serious person" , "serious panda","curious student","curious art student", "obnoxious web developer"}; char localBuffer[BUFLEN]; int allVowelsPresent; void *checker(void *param) { int a=0, e=0, i=0, o = 0, u= 0 ; int* n = (int*)param; // typecasting a void* to int* //printf("%d\n",*n); for (int q=0; q< (*n); ++q) { // dereferencing to get the...
Please debug the code and answer the questions: #include <stdio.h> typedef struct node { int value;...
Please debug the code and answer the questions: #include <stdio.h> typedef struct node { int value; struct node *next; } node; int ll_has_cycle(node *first) { node * head = first; while (head->next) { head = head->next; if (head == first) return 1; } return 0; } void test_ll_has_cycle(void) { int i,j; node nodes[5]; for(i=0; i < sizeof(nodes)/sizeof(node); i++) { nodes[i].next = NULL; nodes[i].value = i; } nodes[0].next = &nodes[1]; nodes[1].next = &nodes[2]; nodes[2].next = &nodes[1]; printf("Checking first list for cycles....
Below is for C language typedef struct _node { Node *next; char *str; } Node; You...
Below is for C language typedef struct _node { Node *next; char *str; } Node; You are given a function that takes in two Node* pointers to two different linked lists. Each linked list node has a string represented by a character array that is properly null terminated. You're function is supposed to return true if the concatenation of strings in a linked list match each other, else return false. EXAMPLES List 1: "h" -> "el" -> "l" -> "o"...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT