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

  Generate the tables attach the primary key and foreign key

Generate the tables attach the primary key and foreign key

  What does this following algorithm calculate

What does this following algorithm calculate

  Problem on boolean calculator

Problem on Boolean Calculator

  Security vulnerability

What is the security vulnerability of this solution

  Write down a program to solve linear system

Write down a program to solve linear system

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Accessing and reading a mouse

Accessing and reading a mouse

  Illustrate general network design

Illustrate general network design

  Illustrate precedence graph

Illustrate precedence graph

  How to generate a hub-and-spoke network

How to generate a hub-and-spoke network

  Write down program that models an employee

Write down program that models an employee

  What is the idea to observe multiple print queues

What is the idea to observe multiple print queues

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