3,318 views

1 Answer

Best answer
11 votes
11 votes

Here, we are modifying an integer variable using a char pointer. The modification happens to the second byte (from the left of the starting location) and it is changed to 2. 

i.e., 300 will be stored as (lower address on left) on a big endian machine

0 * 224 0 * 216 1 * 28 44 * 20

and as 

44 * 20 1 * 28 0 * 216 0 *224

on a little endian machine.

In both the cases using the char pointer we point to the starting byte. And we are incrementing the starting byte by 2. 

Ao, after the increment we have 

0 * 224 2 * 216 1 * 28 44 * 20

on big endian architectures and

44 * 20 2 * 28 0 * 216 0 *224

on little endian architectures. 

The respective values are 131372 and 556.

(This is the most common method of checking if an architecture is little endian or big endian)

selected by

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
2
Anjana Babu asked Jan 8, 2017
556 views
In a 16-bit machine Size of Int Size of pointer are same ? What I knew is 8bit = 1BChar will take - 1 BInt - 2B if integer pointer size is p then size of flot / double ...
0 votes
0 votes
1 answer
3
radha gogia asked Jul 28, 2015
974 views
int * p(void) { int *x; *x=10; return (x); } We create *x, and dereference it before assigning anything to it (x). Most likely, when we are declaring something on the sta...
0 votes
0 votes
1 answer
4
neha singh asked Mar 5, 2017
1,757 views
static char{}="NO SUBSTITUTE FOR HARD WORK";Printf("%10.5s", wer);Outputsa) NO SUB) NO SUBSTITC) UTE F