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

  Why we have a divide databases and data warehouse

Why we have a divide databases and data warehouse

  What are pros and cons of society''s increasing reliance data

What are pros and cons of society's increasing reliance data

  Explore paper on vmware security

Explore paper on VMware Security

  Findout which one is false statement

Findout which one is false statement.

  What is bobs private key

What is Bob's private key?

  Write a research report on design of a cisco router

Systems research and investigate novel ideas and applications.

  Advantages and disadvantages of implementing a dfs

Advantages and disadvantages of implementing a DFS

  What is the advantage when target is throughput and security

What is the advantage when target is throughput and securityty

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Microsoft windows 2000 has domains alpha, beta, and omega

Microsoft Windows 2000  has domains ALPHA, BETA, and OMEGA

  Write a program that reads n positive numbers from keyboard

Write a program that reads N Positive numbers from keyboard

  Design a data structure which supports two operations

Design a data structure which supports two operations 1. Insert(S, x) inserts x into S. 2. Remove-Duplicates(S) removes from S all duplicated values.

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