473,659 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12940
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.hel sinki.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********@yaho o.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********@yaho o.com (nilesh) wrote in message news:<29******* *************** **@posting.goog le.com>...
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
56182
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
5910
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 printed will it be all 0's or 0x12345678 int main(void) { char *ptr; ptr = 0;
10
4031
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 What's wrong with this ? If I use, &((struct my_struct *)0)->member_name, it works. But it seems
7
6744
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
5635
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 expects type 'void *; but argument 2 has type 'void
9
3012
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 accordingly ? I have this doubt as different pointers may have different representation and different size. So, how does printf determine
8
5887
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 clients (Internet Explorer). My flash content was originally brought in via the “flash satay” method, but I have since used some server-side magic do deliver one <objecttag
0
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8850
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8523
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2749
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.