@Subramanian-- great man, thanx alot. actually what I does is I had define array3 inside the main function instead of globally, you had told me to define array3 globally but by mistake I defined it inside the main function which was my fault... thanx alot brother.
On Wed, Aug 3, 2011 at 1:36 PM, Thavasi Subramanian <[email protected]>wrote: > > @Alam, Try this revised code > > #include<stdio.h> > #include<conio.h> > int array3[10]; > main() > { > clrscr(); > int *take,i; > int array1[10]={1,2,3,4,5,6,7,8,9,10}; > int* modify(int*); > take=modify(array1); > for(i=0;i<10;i++) > printf("%d ",*(take+i)); > getch(); > } > > > int* modify(int* array2) > { > int i; > for(i=0;i<10;i++) > { > array3[i]=3*array2[i]; > // printf(" %d",array3[i]); > } > return array3; > } > > > On 3 August 2011 13:31, Thavasi Subramanian <[email protected]> wrote: > >> @Alam: Can u mail tat revised code >> >> >> On 3 August 2011 11:54, Arshad Alam <[email protected]> wrote: >> >>> >>> @Subramanian, I made the changes what you have told, it is running >>> fine,not giving any warning or error but output is not desirable >>> >>> >>> On Wed, Aug 3, 2011 at 11:41 AM, Thavasi Subramanian < >>> [email protected]> wrote: >>> >>>> Here take is a pointer local to fn main() and array3[10] is local to fn >>>> modify. So array3's entire locations are not visible to main(). >>>> "return array3" will retun only the reference of the first element of >>>> the array. >>>> So the pointer will store only one value 3(the first value in array3) in >>>> address "take". >>>> >>>> The problem here is the scope of array3. If you declare array3 as a >>>> global variable then you will get what you are in need of. >>>> >>>> >>>> On 3 August 2011 10:57, Arshad Alam <[email protected]> wrote: >>>> >>>>> WHY THERE IS ERROR AT THE "BOLD LINE" THAT IS L-VALUE REQUIRED >>>>> >>>>> /* >>>>> Write a program which performs the following tasks: >>>>> - initialize an integer array of 10 elements in main( ) >>>>> - pass the entire array to a function modify( ) >>>>> - in modify( ) multiply each element of array by 3 >>>>> - return the control to main( ) and print the new array elements in >>>>> main( ) >>>>> */ >>>>> >>>>> #include<stdio.h> >>>>> #include<conio.h> >>>>> void main() >>>>> { >>>>> clrscr(); >>>>> int take[10],i; >>>>> int array1[10]={1,2,3,4,5,6,7,8,9,10}; >>>>> int* modify(int*); >>>>> *take=modify(array1);* >>>>> for(i=0;i<10;i++) >>>>> printf("%d ",take[i]); >>>>> getch(); >>>>> } >>>>> >>>>> >>>>> int* modify(int* array2) >>>>> { >>>>> int i; >>>>> int array3[10]; >>>>> for(i=0;i<10;i++) >>>>> { >>>>> array3[i]=3*array2[i]; >>>>> // printf(" %d",array3[i]); >>>>> } >>>>> return array3; >>>>> } >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Algorithm Geeks" group. >>>>> To post to this group, send email to [email protected]. >>>>> To unsubscribe from this group, send email to >>>>> [email protected]. >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>> >>>> >>>> >>>> >>>> -- >>>> Thavasi >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to [email protected]. >>>> To unsubscribe from this group, send email to >>>> [email protected]. >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> >> >> -- >> Thavasi >> > > > > -- > Thavasi > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
