Re: [algogeeks] pointer and array

2010-08-03 Thread Raj N
array is passed a pointer in the function, hence sizeof(arr)==sizeof(*arr)

On Fri, Jul 23, 2010 at 9:10 PM, tarak mehta tarakmeht...@gmail.com wrote:

 int arr[]={1,2,3,4};
 k=sizeof(arr)/sizeof(*arr);
 value of k=4;

 however


 void hell(int arr[]);
 main()
 {
int arr[]={1,2,3,4};
hell(arr);
 }
 void hell(int arr[])
 {
 printf(%d,sizeof(arr)/sizeof(*arr));
 }


 output of hell() is 1. why???

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] pointer and array

2010-07-25 Thread padmanaban sahadevan
@tarak mehta:  if u wanna understand, try passing a char array to a function
n do de same...

On Sun, Jul 25, 2010 at 9:59 AM, Manjunath Manohar manjunath.n...@gmail.com
 wrote:


 @Apporve... yeah u r right :)sizeof ptr is always 2 in 16 bit compilers,
 i.e, the sizeof an address is 2.and the sizeof(int)=2..i.e
 sizeof(*arr)=2..hope u got it now..

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] pointer and array

2010-07-24 Thread jalaj jaiswal
sizeof(arr) is 4.. o.e the number of elements in the array
size of *arr is the size of any normal pointer i.e 4(in case of 32-bit
compilers)
so the answer is 1

On Sat, Jul 24, 2010 at 9:52 AM, ravi gupta ravikant0...@gmail.com wrote:



 On Sat, Jul 24, 2010 at 9:40 AM, tarak mehta tarakmeht...@gmail.comwrote:

 int arr[]={1,2,3,4};
 k=sizeof(arr)/sizeof(*arr);
 value of k=4;

 however


 void hell(int arr[]);
 main()
 {
int arr[]={1,2,3,4};
hell(arr);
 }
 void hell(int arr[])
 {
 printf(%d,sizeof(arr)/sizeof(*arr));
 }


 output of hell() is 1. why???

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

 When array is passed as an argument, only a pointer to the first element
 of the array is passed. Therefore the parameter int arr[] in void hell(int
 arr[]) is just a pointer, hence the result .
 I hope it answers your query.

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
With Regards,
Jalaj Jaiswal
+919026283397
B.TECH IT
IIIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] pointer and array

2010-07-24 Thread Manjunath Manohar
when arrays are passed as arguments to a function,the starting address of
the array is passed like a pointer,
thus sizeof(arr)=2..thus 2/2=1..this is the precise reason for always
specifying the column length in the definition of function when functions
have arrays as one of the arguments..

Hope i made any sense.. :)

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] pointer and array

2010-07-24 Thread tarak mehta
void hell(int arr[]);
main()
{
   int arr[]={1,2,3,4,5};
   hell(arr);
}
void hell(int arr[])
{
printf(%d,sizeof(arr)/sizeof(*arr));
}
even this gives 1 !!
@manjunath ur idea seems correct..but could u plz elaborate a bit



On Sat, Jul 24, 2010 at 10:51 PM, Manjunath Manohar 
manjunath.n...@gmail.com wrote:



 when arrays are passed as arguments to a function,the starting address of
 the array is passed like a pointer,
 thus sizeof(arr)=2..thus 2/2=1..this is the precise reason for always
 specifying the column length in the definition of function when functions
 have arrays as one of the arguments..

 Hope i made any sense.. :)

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] pointer and array

2010-07-24 Thread Apoorve Mohan
@tarak:

You can see it like this. When we create an array then 'a' points to the
whole array not just the first element so it returns the size of the whole
array.

when you pass the array though by default in c it is pass by value but as
you are passing the address of the array so it acts like pass by reference.
So the formal parameter acts as a pointer when you pass the address of the
array to it.

And you know that the size of a pointer is always equal to the size of int.



On Sun, Jul 25, 2010 at 12:31 AM, tarak mehta tarakmeht...@gmail.comwrote:

 void hell(int arr[]);
 main()
 {
int arr[]={1,2,3,4,5};


hell(arr);
 }
 void hell(int arr[])
 {
 printf(%d,sizeof(arr)/sizeof(*arr));
 }
 even this gives 1 !!
 @manjunath ur idea seems correct..but could u plz elaborate a bit



 On Sat, Jul 24, 2010 at 10:51 PM, Manjunath Manohar 
 manjunath.n...@gmail.com wrote:



 when arrays are passed as arguments to a function,the starting address of
 the array is passed like a pointer,
 thus sizeof(arr)=2..thus 2/2=1..this is the precise reason for always
 specifying the column length in the definition of function when functions
 have arrays as one of the arguments..

 Hope i made any sense.. :)

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
regards

Apoorve Mohan

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] pointer and array

2010-07-24 Thread Manjunath Manohar
@Apporve... yeah u r right :)sizeof ptr is always 2 in 16 bit compilers,
i.e, the sizeof an address is 2.and the sizeof(int)=2..i.e
sizeof(*arr)=2..hope u got it now..

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] pointer and array

2010-07-23 Thread ravi gupta
On Sat, Jul 24, 2010 at 9:40 AM, tarak mehta tarakmeht...@gmail.com wrote:

 int arr[]={1,2,3,4};
 k=sizeof(arr)/sizeof(*arr);
 value of k=4;

 however


 void hell(int arr[]);
 main()
 {
int arr[]={1,2,3,4};
hell(arr);
 }
 void hell(int arr[])
 {
 printf(%d,sizeof(arr)/sizeof(*arr));
 }


 output of hell() is 1. why???

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

 When array is passed as an argument, only a pointer to the first element of
the array is passed. Therefore the parameter int arr[] in void hell(int
arr[]) is just a pointer, hence the result .
I hope it answers your query.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.