Question 2: Second, linked to the first, how do I pass an array so that it copies itself?
Question 3: Lastly, the below code is giving me problems. The compiler whines that "line 36: error: lvalue required as increment operand". I know what the compiler is telling me, but I don't see why channels++ won't work...it works in the display_b() function.
Code in question
for(i=0;i<ARRAYSIZE;i++)
{
printf("Address: %p\tValue: %d\tMemory Space: %d bytes\n",&(*channels),*channels,sizeof(*channels));
channels++;
}
Full code (i have the channels++; line commented out so it compiles and runs so you can see what I'm trying to do)
#include <stdio.h>
#define ARRAYSIZE 7
//FUNCTION PROTOTYPES
void display_basicvariable(int x);
void display_a(int inputArray[]);
void display_b(int inputArray[]);
//MAIN FUNCTION
int main()
{
int channels[ARRAYSIZE]={2,4,5,7,9,11,13};
int i;
int p = 0;
printf("=======================");
printf("\tRegular Variable outside of function (display_basicvariable()) scope\n");
printf("Address: %p\tValue: %d\t Memory Space: %d bytes\n",&p,p,sizeof(p));
printf("=======================");
printf("\tRegular Variable inside of function (display_basicvariable()) scope\n");
display_basicvariable(p);
printf("=======================");
printf("\tArray outside of function (display_a()) scope (using *channel+i)\n");
for(i=0;i<ARRAYSIZE;i++)
{
printf("Address: %p\tValue: %d\tMemory Space: %d bytes\n",(void *)(channels+i),*(channels+i),sizeof(*channels+i));
}
printf("=======================");
printf("\tArray inside of function (display_a()) scope (using *channels+i)\n");
display_a(channels);
printf("=======================");
printf("\tArray outside of function (display_a()) scope (using *channels)\n");
for(i=0;i<ARRAYSIZE;i++)
{
printf("Address: %p\tValue: %d\tMemory Space: %d bytes\n",&(*channels),*channels,sizeof(*channels));
//channels++;
}
printf("=======================");
printf("\tArray inside of function (display_b()) scope (using *channels)\n");
display_b(channels);
printf("=======================\n");
return 0;
}
//FUNCTION DEFINITIONS
void display_basicvariable(int x)
{
printf("Address: %p\tValue: %d\t Memory Space: %d bytes\n",&x,x,sizeof(x));
}
void display_a(int inputArray[])
{
int i;
for(i=0;i<ARRAYSIZE;i++)
{
printf("Address: %p\tValue: %d\tMemory Space: %d bytes\n",(void *)(inputArray+i),*(inputArray+i),sizeof(*inputArray+i));
}
}
void display_b(int inputArray[])
{
int i;
for(i=0;i<ARRAYSIZE;i++)
{
printf("Address: %p\tValue: %d\tMemory Space: %d bytes\n",&(*inputArray),*inputArray,sizeof(*inputArray));
inputArray++;
}
}

New Topic/Question
Reply




MultiQuote




|