1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
KonstantinChe [14]
3 years ago
13

Write a C program that does a large number of references to elements of two-dimensioned arrays, using only subscripting. Write a

second program that does the same operations but uses pointers and pointer arithmetic for the storage-mapping function to do the array references. Compare the time efficiency of the two programs. Which of the two programs is likely to be more reliable

Computers and Technology
1 answer:
telo118 [61]3 years ago
6 0

Answer:

#include <stdio.h>

#include <time.h>

int main()

{

 

clock_t start, end;

double cpu_time_used;

 

//starting the cpu clock.

start = clock();

 

for(int i=0; i<10000; i++){

my_func_with_only_subscript();    

}

 

// closing the cpu clock.

end = clock();

 

// calculating time elapsed in secs.

cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;

 

printf("Time taken with subscript references::%f\n",cpu_time_used);

 

// starting the cpu clock

start = clock();

 

for(int i=0; i<10000; i++){

my_func_with_pointers();

}

 

// closing the cpu clock.

end = clock();

 

// calculating the time elapsed in array reference through pointers.

cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;

 

printf("Time taken with pointers::%f\n",cpu_time_used);

 

return 0;

}

// function to reference the 2D array through subscripts.

void my_func_with_only_subscript()

{ //assuming that the usage of

int arr[15][5] = {0}; //square matrice is not mandatory

for(int j=0; j<5 ; j++){

for(int i=0; i<15; i++){

arr[i][j]; //no operation is done, only accessing the element

}

}

return;

}

// function to reference the 2D array through pointers.

void my_func_with_pointers()

{ //assuming that the usage of

int arr[15][5] = {0}; //square matrice is not mandatory

for(int j=0; j<5 ; j++){

for(int i=0; i<15; i++){

*(*(arr+i)+j); //no operation is done, only accessing the element

}

}

return;

}

/******************************************************************************************************************************/

OUTPUT

[Attached in the attachments]

You might be interested in
20
denis-greek [22]

Answer:

true

Explanation:

because my 8 ball said so

6 0
4 years ago
When a policy setting in Computer Configuration and User Configuration in the same GPO conflict, the Computer Configuration poli
Maru [420]

Answer:

True

Explanation:

Computer Configuration policy applied first. This happens when the Computer system boots up. Then the user policy is applied when the user logs on. This takes place when the user object is in the same organizational unit.

So Computer Config policy setting takes precedence. User configurations is applied to local users only while computer configuration is applied to the machine itself. First the Computer GPO is applied and then the User GPO.  Loopback processing in replace mode enforces the Computer GPO over the user GPO.

8 0
4 years ago
The general case in a recursive function is the case for which the solution is obtained directly.
Reika [66]

Answer: False.

Explanation:

The general case of recursive function is when the solution is obtained recursively by simplification at each step.

However, it is the base case in a recursive function when the solution is obtained directly.

The general case must be reducible to base to arrive at a solution else the recursion would be a infinite recursion.

4 0
3 years ago
Describe personal computer skills using three adjectives?
Volgvan

Answer:

proficient with Microsoft word Excel and PowerPoint

Explanation:

compost and send over 150 images microsoftop creating and the formatting simple office budget speed sheets on Microsoft Excel Bros and its documents Microsoft word

5 0
2 years ago
Read 2 more answers
For each of the following scenarios, write down what feature should be used in
inessss [21]

Answer:

d

Explanation:

5 0
3 years ago
Other questions:
  • 3.A customer has a system with a Gigabyte B450 Aorus Pro motherboard. He wants to upgrade the processor from the AMD Athlon X4 9
    11·1 answer
  • Write a class that can make comparisons between the efficiency of the common methods from the List interface in the ArrayList an
    5·1 answer
  • Basically, if for every row, the absolute value of the entry along the main diagonal is larger than the sum of the absolute valu
    10·1 answer
  • What is the purpose of the operating systems management function
    5·1 answer
  • PLEASE FASTTTTT
    8·2 answers
  • There are many advantages and some disadvantages to using social media. Explain at least one of the advantages to
    5·1 answer
  • If you forget your privacy password what will you do if the ask this question what is the name of one of your teacher?​
    12·1 answer
  • What are the three types of networks?
    13·2 answers
  • One vulnerability that makes computers susceptible to walmare is:
    13·2 answers
  • 15. How many PC’s can be connected to a UPS?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!