Re: [algogeeks] What would be the output for the following code fragment?

2012-06-07 Thread atul anand
i=300 // binary = 0001 00101100
// in case of little Endien
it will be saved like this :-
0001
00101100
//suppose int = 2 bytes and char = 1 byte
char *ptr = i; // take care it *char *ptr* not *int* **ptr*so what
will happen

*ptr will be pointing to 00101100

*++ptr // now ptr is pointing to 0001 bcozz it is a char * hence it
will be increment by 1 byte
ptr=2 // now 0001 will be converted to 0010

so final value of i becomes 001000101100 = 556

now you can try for big endian 

On Thu, Jun 7, 2012 at 12:27 AM, g4ur4v gauravyadav1...@gmail.com wrote:



 main()
 {
 int i=300;
 char *ptr = i;
 *++ptr=2;
 printf(%d,i);
 }

 --
 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] What would be the output for the following code fragment?

2012-06-07 Thread s yogeesh
A: 556

-- 
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] What would be the output for the following code fragment?

2012-06-07 Thread Prem Krishna Chettri
Hahaha.. Xcellent question Dude.. People Who Know can easily explain.. So
for who don't here it is..

It has nothing to do with Endianess Mr.Yogesh.. Actually the bit patter
happens to be reside such that ob.ch[0] fills with all ones ..

Now as we knw the sign bit concept , here compilers goes mad thinking that
the first 1 of 8 consecutive 1's for 255 number as the Sign bit and does
the required operation of transforming to equivalent positive integer which
happen to be 1..

So as I said no endian here.. if u change the machine than U'll get other
-1 .i.e. ch[1]=-1 and again ch[0]=0..

BR,
Prem

On Thu, Jun 7, 2012 at 11:14 AM, s yogeesh yogees...@gmail.com wrote:

 A: 556

 --
 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] What would be the output for the following code fragment?

2012-06-07 Thread s yogeesh
Sign bit.
well i forgot abt that. Bro still nly 1 bit s taken for sign so nly 1 '1' s
taken as determining sign to be negative. Still we have 7 1's in hand.
Wat abt that ?

-- 
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.



[algogeeks] What would be the output for the following code fragment?

2012-06-06 Thread g4ur4v


main()
{
int i=300;
char *ptr = i;
*++ptr=2;
printf(%d,i);
}

-- 
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] What would be the output for the following code fragment?

2012-06-06 Thread Abhishek Sharma
http://ideone.com/Zz7ET

On Thu, Jun 7, 2012 at 12:27 AM, g4ur4v gauravyadav1...@gmail.com wrote:



 main()
 {
 int i=300;
 char *ptr = i;
 *++ptr=2;
 printf(%d,i);
 }

 --
 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.




-- 
Abhishek Sharma
Under-Graduate Student,
PEC University of Technology

-- 
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.