why two loops, find max and min and returns its difference surender
On Fri, Jul 1, 2011 at 11:32 AM, sunny agrawal <[email protected]>wrote: > in function it is pointer pointing to an array of 6 elements , pointer have > size equal to word size in the system which is 4bytes for 32 bit operating > system > > in main it is array of 6 integers so 24 bytes > > Don't get confused with same names, see the scope and type of arr in both > > > On Fri, Jul 1, 2011 at 11:28 AM, shady <[email protected]> wrote: > >> why is the value of sizeof(arr) in maxdiff function = 4 ? >> where as in main function it is 24 >> >> >> On Fri, Jul 1, 2011 at 11:05 AM, Vishal Thanki <[email protected]>wrote: >> >>> Rujin is right, here is the code which compiles.. >>> >>> vishal@ubuntu:~/progs/c\ 11:04:37 AM >$ cat alg.c >>> #include<stdio.h> >>> int maxdiff(int arr[]); >>> int main() >>> { >>> int p,arr[]={2,4,1,6,23,4}; >>> p=maxdiff(arr); >>> printf("\n MAX Diff is \t %d",p); >>> return 0; >>> } >>> int maxdiff(int arr[]) >>> { >>> int diff=0,len,i,j; >>> unsigned p; >>> len=sizeof(arr)/sizeof(arr[0]); >>> for(i=0;i<len;i++) >>> { >>> for(j=i;j<len;j++) >>> { >>> p=arr[j]-arr[i]; >>> if((p-diff)>0) >>> diff=p; >>> } >>> } >>> return diff; >>> } >>> vishal@ubuntu:~/progs/c\ 11:04:40 AM >$ gcc alg.c -Wall >>> >>> >>> On Fri, Jul 1, 2011 at 7:20 AM, varun pahwa <[email protected]> >>> wrote: >>> > actually u r passing arr,and receiving arr[] which actually receives >>> the >>> > first element address. So arr will be a reference to first address. so >>> its >>> > size will be 4 bytes and arr size will also be 4 bytes. so ur len >>> contains >>> > only 1. so ur loop runs only once.i hope it clears. >>> > >>> > On Thu, Jun 30, 2011 at 4:49 PM, ashwini singh <[email protected]> >>> wrote: >>> >> >>> >> still it's not working >>> >> >>> >> On Thu, Jun 30, 2011 at 4:42 PM, Rujin Cao <[email protected]> >>> wrote: >>> >>> >>> >>> int maxdiff(int ); >>> >>> int maxdiff(int arr[]); >>> >>> The signatures of maxdiff function are not the same. >>> >>> >>> >>> On Fri, Jul 1, 2011 at 6:53 AM, ashwini singh <[email protected]> >>> >>> wrote: >>> >>>> >>> >>>> this code gives an error ([Warning] passing arg 1 of `maxdiff' makes >>> >>>> integer from pointer without a cast) . Please explain the reasons. >>> >>>> >>> >>>> >>> >>>> #include<stdio.h> >>> >>>> #include<conio.h> >>> >>>> int maxdiff(int ); >>> >>>> main() >>> >>>> { >>> >>>> int p,arr[]={2,4,1,6,23,4}; >>> >>>> p=maxdiff(arr); >>> >>>> printf("\n MAX Diff is \t %d",p); >>> >>>> getch(); >>> >>>> } >>> >>>> int maxdiff(int arr[]) >>> >>>> { >>> >>>> int diff=0,len,i,j; >>> >>>> unsigned p; >>> >>>> len=sizeof(arr)/sizeof(arr[0]); >>> >>>> for(i=0;i<len;i++) >>> >>>> { >>> >>>> for(j=i;j<len;j++) >>> >>>> { >>> >>>> p=arr[j]-arr[i]; >>> >>>> if((p-diff)>0) >>> >>>> diff=p; >>> >>>> } >>> >>>> } >>> >>>> return diff; >>> >>>> } >>> >>>> >>> >>>> -- >>> >>>> with regards, >>> >>>> Ashwini kumar singh >>> >>>> ECE Final yr. >>> >>>> NIT Allahabad >>> >>>> >>> >>>> >>> >>>> -- >>> >>>> 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. >>> >> >>> >> >>> >> >>> >> -- >>> >> with regards, >>> >> Ashwini kumar singh >>> >> ECE Final yr. >>> >> MNNIT Allahabad >>> >> Mobile: 7505519402 >>> >> >>> >> -- >>> >> 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. >>> > >>> > >>> > >>> > -- >>> > Varun Pahwa >>> > B.Tech (IT) >>> > 7th Sem. >>> > Indian Institute of Information Technology Allahabad. >>> > Ph : 09793899112 ,08011820777 >>> > Official Email :: [email protected] >>> > Another Email :: [email protected] >>> > >>> > People who fail to plan are those who plan to fail. >>> > >>> > -- >>> > 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. >>> >>> >> -- >> 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. >> > > > > -- > Sunny Aggrawal > B-Tech IV year,CSI > Indian Institute Of Technology,Roorkee > > -- > 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.
