[algogeeks] C o/p help

2012-01-26 Thread rahul sharma
#includestdio.h
#includeconio.h
void fun(char **);

int main()
{
char *argv[]={ab,cd,de,fg};
fun(argv);
getch();
return 0;
}

void fun(char **p)
{
 char *t;
 t=(p+=sizeof(int))[-1];
 printf(%s\n,t);
}

o/p: fg

can nyone xplain

the 2nd statement in fun?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] C o/p help

2012-01-26 Thread atul anand
output depends on sizeof(int)so it may be different if you run on
different compilers.

considering *sizeof(int) = 2;*

argv[] is array of pointers.
  (p+=sizeof(int))[-1];
p=p+2 // 2=sizeof(int);

now p will be pointing at index *argv[2];
then you are doing

p=p-1;

i.e p will point to *argv[1]

hence output will be
o/p = cd

On Thu, Jan 26, 2012 at 10:53 PM, rahul sharma rahul23111...@gmail.comwrote:

 #includestdio.h
 #includeconio.h
 void fun(char **);

 int main()
 {
 char *argv[]={ab,cd,de,fg};
 fun(argv);
 getch();
 return 0;
 }

 void fun(char **p)
 {
  char *t;
  t=(p+=sizeof(int))[-1];
  printf(%s\n,t);
 }

 o/p: fg

 can nyone xplain

 the 2nd statement in fun?

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] C o/p help

2012-01-26 Thread atul anand
btw your compiler has sizeof(int)=4;
thats why o/p = fg

On Thu, Jan 26, 2012 at 11:09 PM, atul anand atul.87fri...@gmail.comwrote:

 output depends on sizeof(int)so it may be different if you run on
 different compilers.

 considering *sizeof(int) = 2;*

 argv[] is array of pointers.
   (p+=sizeof(int))[-1];
 p=p+2 // 2=sizeof(int);

 now p will be pointing at index *argv[2];
 then you are doing

 p=p-1;

 i.e p will point to *argv[1]

 hence output will be
 o/p = cd

 On Thu, Jan 26, 2012 at 10:53 PM, rahul sharma rahul23111...@gmail.comwrote:

 #includestdio.h
 #includeconio.h
 void fun(char **);

 int main()
 {
 char *argv[]={ab,cd,de,fg};
 fun(argv);
 getch();
 return 0;
 }

 void fun(char **p)
 {
  char *t;
  t=(p+=sizeof(int))[-1];
  printf(%s\n,t);
 }

 o/p: fg

 can nyone xplain

 the 2nd statement in fun?

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] C o/p help

2012-01-26 Thread rahul sharma
[-1] in end is same as -1 ??

On Thu, Jan 26, 2012 at 11:11 PM, atul anand atul.87fri...@gmail.comwrote:

 btw your compiler has sizeof(int)=4;
 thats why o/p = fg

 On Thu, Jan 26, 2012 at 11:09 PM, atul anand atul.87fri...@gmail.comwrote:

 output depends on sizeof(int)so it may be different if you run on
 different compilers.

 considering *sizeof(int) = 2;*

 argv[] is array of pointers.
   (p+=sizeof(int))[-1];
 p=p+2 // 2=sizeof(int);

 now p will be pointing at index *argv[2];
 then you are doing

 p=p-1;

 i.e p will point to *argv[1]

 hence output will be
 o/p = cd

 On Thu, Jan 26, 2012 at 10:53 PM, rahul sharma 
 rahul23111...@gmail.comwrote:

 #includestdio.h
 #includeconio.h
 void fun(char **);

 int main()
 {
 char *argv[]={ab,cd,de,fg};
 fun(argv);
 getch();
 return 0;
 }

 void fun(char **p)
 {
  char *t;
  t=(p+=sizeof(int))[-1];
  printf(%s\n,t);
 }

 o/p: fg

 can nyone xplain

 the 2nd statement in fun?

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.



  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] C o/p help

2012-01-26 Thread atul anand
think in terms of pointers...

they are same :-

p[-1] = *(p - 1)

On Thu, Jan 26, 2012 at 11:15 PM, rahul sharma rahul23111...@gmail.comwrote:

 [-1] in end is same as -1 ??


 On Thu, Jan 26, 2012 at 11:11 PM, atul anand atul.87fri...@gmail.comwrote:

 btw your compiler has sizeof(int)=4;
 thats why o/p = fg

 On Thu, Jan 26, 2012 at 11:09 PM, atul anand atul.87fri...@gmail.comwrote:

 output depends on sizeof(int)so it may be different if you run on
 different compilers.

 considering *sizeof(int) = 2;*

 argv[] is array of pointers.
   (p+=sizeof(int))[-1];
 p=p+2 // 2=sizeof(int);

 now p will be pointing at index *argv[2];
 then you are doing

 p=p-1;

 i.e p will point to *argv[1]

 hence output will be
 o/p = cd

 On Thu, Jan 26, 2012 at 10:53 PM, rahul sharma 
 rahul23111...@gmail.comwrote:

 #includestdio.h
 #includeconio.h
 void fun(char **);

 int main()
 {
 char *argv[]={ab,cd,de,fg};
 fun(argv);
 getch();
 return 0;
 }

 void fun(char **p)
 {
  char *t;
  t=(p+=sizeof(int))[-1];
  printf(%s\n,t);
 }

 o/p: fg

 can nyone xplain

 the 2nd statement in fun?

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.



  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] C o/p help

2012-01-26 Thread rahul sharma
@ atul...got nw..thnx

On Thu, Jan 26, 2012 at 11:26 PM, atul anand atul.87fri...@gmail.comwrote:

 think in terms of pointers...

 they are same :-

 p[-1] = *(p - 1)


 On Thu, Jan 26, 2012 at 11:15 PM, rahul sharma rahul23111...@gmail.comwrote:

 [-1] in end is same as -1 ??


 On Thu, Jan 26, 2012 at 11:11 PM, atul anand atul.87fri...@gmail.comwrote:

 btw your compiler has sizeof(int)=4;
 thats why o/p = fg

 On Thu, Jan 26, 2012 at 11:09 PM, atul anand atul.87fri...@gmail.comwrote:

 output depends on sizeof(int)so it may be different if you run on
 different compilers.

 considering *sizeof(int) = 2;*

 argv[] is array of pointers.
   (p+=sizeof(int))[-1];
 p=p+2 // 2=sizeof(int);

 now p will be pointing at index *argv[2];
 then you are doing

 p=p-1;

 i.e p will point to *argv[1]

 hence output will be
 o/p = cd

 On Thu, Jan 26, 2012 at 10:53 PM, rahul sharma rahul23111...@gmail.com
  wrote:

 #includestdio.h
 #includeconio.h
 void fun(char **);

 int main()
 {
 char *argv[]={ab,cd,de,fg};
 fun(argv);
 getch();
 return 0;
 }

 void fun(char **p)
 {
  char *t;
  t=(p+=sizeof(int))[-1];
  printf(%s\n,t);
 }

 o/p: fg

 can nyone xplain

 the 2nd statement in fun?

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.



  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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.