Why array names are not assignable variables in c

Assignment Help Computer Engineering
Reference no: EM133444

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]

Reference no: EM133444

Questions Cloud

A statistical conclusion and audit decision : A statistical conclusion, and the audit decision you could make based on the quantitative sample results.
Configuring a database : Configuring a Database
Accounting information system processes : Implement one of the subsequent accounting information system processes:
Classical conditioning and operant conditioning in learning : classical conditioning and operant conditioning in learning, main techniques of personality assessment,  Atkinson and Shiffrin's Model for memory, techniques of improving memory, utility of a neuron, psychology develop as a methodical field, co-relat..
Why array names are not assignable variables in c : Why  array names are not assignable variables in c
Describe the role of the soap : Describe the three entities and three operations that represent the Web Services model defined by SOA. (Support your answer with a diagram) Describe the role of the following three core Web Service standards- i SOAP ii WSDL iii UDDI
Evaluate the markup required to make the desired return : Use the absorption costing approach to evaluate the markup required to make the desired return on investment based on the subsequent information.
How many prefetches need to be outstanding : How many prefetches need to be outstanding
Evaluate the cost of goods : Evaluate the cost of goods completed and transferred out of the Assembly Department.

Reviews

Write a Review

Computer Engineering Questions & Answers

  How to generate paper for pair of public or private rsa key

How to generate paper for a pair of public or private RSA keys? The high-class reporter for foreign affairs learned about asymmetric cryptography, and proposed to security team at the paper to generate for a pair of public or private RSA keys.

  While running snort ids why may there be no alerts

While running Snort IDS why may there be no alerts

  Write down specification for the adt as a java interface

Write down specification for the ADT as a java interface

  Arrays and control structures important tools in programming

Arrays and control structures important tools in programming.

  What are the roles of the management sponsors

What are the roles of the management sponsors

  Write down mips program that prompts user for a string

Write down MIPS program that prompts user for a string

  How to set a rule that used by snort to detect an ack scan

How to set a rule that used by snort to detect an ACK scan What do you think Bro can do a better job detecting an ACK scan?

  How a box of caramel delites girl scout cookies

How to a box of Caramel deLites Girl Scout cookies Every spring you looking forward to buying a box of Caramel deLites Girl Scout cookies

  Develop a checkout lane simulation

Develop a checkout lane simulation that can be used to determine the optimal number of lanes that Cougar Mart should have open.

  Program on strings s1 and s2

Program on strings s1 and s2.

  Generate the tables attach the primary key and foreign key

Generate the tables attach the primary key and foreign key

  How to create program that performs arithmetic function

How to create program that performs arithmetic function Prompt a user for values for the variables. Pass both variables to methods named sum() and difference().

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd