Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Question

In programming language C, array names are not assignable variables. Therefore, we can't copy an array directly with an assignment statement. As a contrast, objects of struct types can be copied.

The following code snippet illustrates difference:

struct {int i; float f;} x, y;
int a[10], b[10];
y = x; /* Copy x to y, OK */
b = a; /* Illegal assignment */
Now if we wrap an array inside a struct:
typedef int array[5];
typedef struct {array v;} wrapped;
then we can copy a wrapped array with assignment
wrapped wa, wb;
wb = wa; /* Copy wrapped array a to wrapped array b */
Use this idea to implement an array-copying routine:
/* copy (unwrapped) array a to array b */
void array_copy(array a, array b)
{
}

such that when following driver routine executes,

int main()
{
array a = {1,2,3,4,5}, b = {6,7,8,9,10};
printf("Before: b=[%d,%d,%d,%d,%d]n",
b[0],b[1],b[2],b[3],b[4]);
array_copy(a,b);
printf("After: b=[%d,%d,%d,%d,%d]n",
b[0],b[1],b[2],b[3],b[4]);
}

we get the output:
Before: b=[6,7,8,9,10]
After: b=[1,2,3,4,5]

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9133858

Have any Question?


Related Questions in Computer Engineering

Write a program that uses a function that returns a number

Write a program that uses a function that returns a number between 1 and 6. Use this function to simulate the roll of a die. Allow the user to specify the number of trials and then tabulate that number of rolls of two di ...

1i which of the following characterizes a market ordera a

1) i. Which of the following characterizes a market order? a) A market order, which is considered a small order, is when 100 shares of a stock are ordered b) A market order is when the investor specifies the maximum pric ...

You have a deck of magic the gathering cards with 60 cards

You have a deck of Magic the Gathering cards with 60 cards total. In the deck you have 20 Mana cards, 18 Spells, 3 Artifacts, 12 Creatures, 6 Enchantments and 1 Planes Walker. What is the probability that you draw 2 arti ...

The newly elected president needs to decide the remaining 4

The newly elected president needs to decide the remaining 4 spots available in the cabinet he/she is appointing. If there are 13 eligible candidates for these positions (where rank matters), how many different ways can t ...

Suppose a 4 packets of a message each of size 10 mbit

Suppose a 4 packets of a message, each of size 10 Mbit arrive simultaneously at a switch preceding a transmission link of rate 5 Mbps connecting to the destination host. (a) What is the average queuing delay experienced ...

Systems analysis projectpersonal trainer inc owns and

Systems analysis project Personal Trainer, Inc. owns and operates fitness centers in a dozen Midwestern cities. The centers have done well, and the company is planning an international expansion by opening a new "superce ...

Questionusing the cost-benefit analysis method estimate how

Question..... Using the cost-benefit analysis method, estimate how much money MidCorp should spend on power protection. You will have to make several assumptions to do this. Your answer should contain an "assumptions" se ...

Explain why a successful information security program is

Explain why a successful information security program is the shared responsibility of an organizations three communities of interest.

If we compare and contrast the four market structures it is

If we compare and contrast the four market structures, it is evident that one market structure is most practiced and evident in the United States. It is the one that promotes and strives on competition. It is the one tha ...

Why is formative evaluation importantprovide at least three

Why is formative evaluation important? Provide at least three reasons for using it. What is the difference between formative and summative evaluation? Provide any two types formative evaluation and two types of summative ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As