Welcome Guest | Sign in | Register
Pointers - Discussion Page For Q.10774 | C Programming Questions and Answers | C Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Pointers > Questions and Answers

Q: What will be output of following program?

#include
int main()
{
int a = 320;
char *ptr;
ptr = (char *)&a;
printf("%d",*ptr);
return 0;
}
A. 2 B. 320
C. 64 D. Compilation Error

Answer and Explanation

Answer:64

Explanation:
As we know int is two byte data byte while char is one byte data byte. Character pointer can keep the address one byte at time.

Binary value of 320 is 00000001 01000000 (In 16 bit) Memory representation of int a = 320 is:

So ptr is pointing only first 8 bit which color is green and Decimal value is 64. 

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.