CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C DETAILS
Question :
How do you print an address?



Category C Interview Questions
Rating (5.0) By 2 users
Added on 7/19/2006
Views 3134
Rate it!
Answers:

We can print the address of a variable or a function using the following specifiers %u,%p here %u prints address in decimal form and %p prints in hexa decimal form,but remember these two format specifiers print only offset address but they doesn't print code segment address

there is a another specifier %Fp which prints both the code segment and offset address



The address of variable is printed in 'c' by using the formated string "%u" and the variable is '&variable name'.



 Posted by: sreelatha    

Contact sreelatha  Contact sreelatha

Syntax:
printf("%u",&<variable name>);



 Posted by: Neha Vora    

Contact Neha Vora  Contact Neha Vora

int a;
int *p;
p=&a;
printf("%u",p);



 Posted by: Ameya    

Contact Ameya  Contact Ameya

Using printf("%u",p); is wrong. "%u" outputs an unsigned int. unsigned int may not be the same size as a pointer.

Using printf("%p",p) is the only portable method.

sreelatha mentions segment addresses. Segment addressing is architecture specific and the "%Fp" format string is compiler-specific extension.



 Posted by: Joel Corley    

Contact Joel Corley  Contact Joel Corley


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
What is the difference between NULL and NUL?


View Answer
What is the stack?


View Answer
What is a null pointer?


View Answer
How can I convert a number to a string?


View Answer
What is the difference between #include <file> and #include ?file??


View Answer
What is Preprocessor?


View Answer
What is the difference between text and binary modes?


View Answer
What is the benefit of using const for declaring constants?


View Answer
What is the difference between declaring a variable and defining a variable?


View Answer
What is a const pointer?
View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/6067/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

1.67