GATE | GATE MOCK 2017 | Question 44
Consider the following C code
int main()
{
int a = 300;
char *b = (char *)&a;
*++b = 2;
printf("%d ",a);
return 0;
}
Consider the size of int as two bytes and size of char as one byte. Predict the output of the following code .
Assume that the machine is little-endian.
(A) 556
(B) 300
(C) Runtime Error
(D) Compile Time Error
Answer: (A)
Explanation:
Ans is 556 as char pointer will change the second byte of the integer in the memory and when you print it as a whole integer using %d , its value will be 556 considering little endian scenario.
Please read the following link :
http://stackoverflow.com/questions/22030657/little-endian-vs-big-endian
Quiz of this Question
Recommended Posts:
- GATE | GATE MOCK 2017 | Question 33
- GATE | GATE MOCK 2017 | Question 34
- GATE | GATE MOCK 2017 | Question 35
- GATE | GATE MOCK 2017 | Question 36
- GATE | GATE MOCK 2017 | Question 37
- GATE | GATE MOCK 2017 | Question 38
- GATE | GATE MOCK 2017 | Question 39
- GATE | GATE MOCK 2017 | Question 40
- GATE | GATE MOCK 2017 | Question 32
- GATE | GATE MOCK 2017 | Question 31
- GATE | GATE MOCK 2017 | Question 30
- GATE | GATE MOCK 2017 | Question 23
- GATE | GATE MOCK 2017 | Question 24
- GATE | GATE MOCK 2017 | Question 25
- GATE | GATE MOCK 2017 | Question 26



