473,396 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

printing address using pointer

Hello,

I have a basic doubt. Consider following program :

#include<stdio.h>
int main()
{
int i, *ip;
i = 10;
ip = &i;
printf("%x\n", ip);
return 0;
}

When I print the value of ip i.e. the address of integer i, does it
prints the virtual address of integer i or physical address of i ?

TIA
../nilesh
Nov 14 '05 #1
4 12925
nilesh wrote:
int i, *ip;
i = 10;
ip = &i;
printf("%x\n", ip);
I'm not sure the %x is apropriate here....
When I print the value of ip i.e. the address of integer i, does it
prints the virtual address of integer i or physical address of i ?


Since C has no concept of virtual vs physical addresses, it can only print
the address it has a concept of, and that is pretty much only 'a location
in memory'.
I would expect it to print the virtual address though(assuming you have
such a memory model on your machine), since virtual addresses are the
thing every program (except the kernel perhaps) should deal with.

Uli
Nov 14 '05 #2
Ulrich Eckhardt <do******@knuut.de> scribbled the following:
nilesh wrote:
int i, *ip;
i = 10;
ip = &i;
printf("%x\n", ip);
I'm not sure the %x is apropriate here....


It's not. %p is, and ip should be cast to void *.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"I am not very happy acting pleased whenever prominent scientists overmagnify
intellectual enlightenment."
- Anon
Nov 14 '05 #3
On 31 Oct 2004 21:36:54 -0800, ni********@yahoo.com (nilesh) wrote:
Hello,

I have a basic doubt. Consider following program :

#include<stdio.h>
int main()
{
int i, *ip;
i = 10;
ip = &i;
printf("%x\n", ip);
printf("%p\n", (void*)ip);
return 0;
}

When I print the value of ip i.e. the address of integer i, does it
prints the virtual address of integer i or physical address of i ?

TIA
./nilesh


<<Remove the del for email>>
Nov 14 '05 #4
ni********@yahoo.com (nilesh) wrote in message news:<29************************@posting.google.co m>...
Hello,

I have a basic doubt. Consider following program :

#include<stdio.h>
int main()
{
int i, *ip;
i = 10;
ip = &i;
printf("%x\n", ip);
printf ("%p\n", (void*) ip);
return 0;
}

When I print the value of ip i.e. the address of integer i, does it
prints the virtual address of integer i or physical address of i ?


I'm pretty sure that's specific to the implementation; for example, if
you're running a user program on a *nix or Windows platform, it's
almost certainly a virtual address. If you were running on bare
metal, it would probably be a physical address (then again, if you
were running on bare metal, you probably wouldn't have a working
printf() available anyway).
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: weaselboy1976 | last post by:
Hello How can I print a pointer's value directly (without assigning the value to another variable)? For example: #include <stdio.h> int main() { int *zp;
42
by: junky_fellow | last post by:
Consider an implementation that doesn't use all bits 0 to represent a NULL pointer. Let the NULL pointer is represented by 0x12345678. On such an implementation, if the value of NULL pointer is...
10
by: junky_fellow | last post by:
I am trying to print the offset of a particulat member in a structure, but it's not working. I am using the following expression to print the offset. &(struct my_struct *)0->member_name ...
7
by: salmonella | last post by:
Hi, I'm trying to print on screen an address of class member function (the function of certain object of course). My code looks like this: class MyClass { public: void fun(void){}; };
57
by: Robert Seacord | last post by:
i am trying to print the address of a function without getting a compiler warning (i am compiling with gcc with alot of flags). if i try this: printf("%p", f); i get: warning: format %p...
9
by: junky_fellow | last post by:
Hi, To print the pointer using printf(), we convert it to (void *) . printf("%p",(void *)ptr); My question is how printf() determine which type of pointer is passed to it and prints its value...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.