Re: [algogeeks] c code.....explaine output

2010-06-21 Thread jalaj jaiswal
@above 2 ... nice explanation both of you On Mon, Jun 21, 2010 at 10:31 AM, manisha nandal wrote: > int main() > { > int a=7,b=2; > char* p=(char*)a; > > printf("%p",p); //prints 00 00 00 07 > printf("\n%p",p+2); //prints 00 00 00 09 > > int s=(int)&p[b];//converted to &( *(p

Re: [algogeeks] c code.....explaine output

2010-06-20 Thread manisha nandal
int main() { int a=7,b=2; char* p=(char*)a; printf("%p",p); //prints 00 00 00 07 printf("\n%p",p+2); //prints 00 00 00 09 int s=(int)&p[b];//converted to &( *(p+b)) i.e p+b same as above printf("\n%d",s); // 9 } hope its clear now -- You received this message becau

Re: [algogeeks] c code.....explaine output

2010-06-20 Thread Debajyoti Sarma
p=(char *)a; this statement assigns value of 7 to p after type converting to char*, so as p is a pointer it points to memory location 7 p[b] will give to the value at location 9 same as *(p+b) = *(7 + 2) just like array &p[b] will give the address of that location i.e. 9 which is char* so we type

Re: [algogeeks] c code.....explaine output

2010-06-20 Thread Debajyoti Sarma
This can be answer for addition for the question 2 numbers without using + operator. Interesting fact is that it works for -ve numbers also.actually it get converted to unsigned and type converted back again to -ve number. #include int main() { int a=-7,b=-2,s; char *p; p=(char *)a; s= (int)&p[b]

Re: [algogeeks] c code.....explaine output

2010-06-20 Thread jalaj jaiswal
@ above all i dint get how the value of a and b gets added in s... after p=(char *)a... p has 7 in it... but how the value gets added thru s=(int)&p[b] p[b] seems as if p is an array.. m confused in this line .. please explain in a bit detail.. :O On Sun, Jun 20, 2010 at 4:44 PM, anan

Re: [algogeeks] c code.....explaine output

2010-06-20 Thread anand verma
thanks -- 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

Re: [algogeeks] c code.....explaine output

2010-06-20 Thread sharad kumar
@anand:he takes the value at particular byte by using char*...same u do for chcking endianess rite...same concept On Sun, Jun 20, 2010 at 3:39 PM, sharad kumar wrote: > @anand:its similar to reference an array element using pointer...*(p+i) > which is imilar to &p[i] when u put *before & the valu

Re: [algogeeks] c code.....explaine output

2010-06-20 Thread sharad kumar
@anand:its similar to reference an array element using pointer...*(p+i) which is imilar to &p[i] when u put *before & the value gets dereferenced and hence p+i takes place same concept On Sun, Jun 20, 2010 at 3:27 PM, anand wrote: > it caculate the sum of two numbers. > > #include > int main() >

[algogeeks] c code.....explaine output

2010-06-20 Thread anand
it caculate the sum of two numbers. #include int main() { int a=7,b=2,s; char *p; p=(char *)a; s= (int)&p[b]; //adding a & b//HOW printf("sum=%d\n",s); return 0; } can any one explain the code..?? -- You received this message because you are subscribed to the Googl