0

For example

printf("%u",&a);

gives me output

65524

which is a 16 bit address.

Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69
nrb
  • 5
  • 8
  • 2
    Not everybody can sit in the front row ... ;-) – alk May 16 '16 at 14:23
  • 2
    0x0000000000000000 is a 64bit address, isn't it? And it's equal 0x0. – alk May 16 '16 at 14:25
  • 1
    "If my computer is a 32 bit system,it has a 32 bit address right?" Likely, but not guaranteed. [See this](http://stackoverflow.com/a/34725569/584518). Also, there is no guarantee that `unsigned int` will be 32 bits. – Lundin May 16 '16 at 14:26
  • 1
    So if you print a variable and get the value `1` would that be a 1 bit variable? And the value `7` a 3 bit variable? No - you can't determine the number of bits available by printing the value. Use `sizeof` – Support Ukraine May 16 '16 at 14:27
  • Just out of curiosity: what is your platform? – LPs May 16 '16 at 14:27
  • There's a difference between "shorter than 32 bit" and "smaller than 2^32-1" – user3528438 May 16 '16 at 14:38
  • @user3528438 - Not when printed with `%u` - you just can't see the number of zeros in front as they are not printed. So you can't tell the actual number of bits - the value may be representable in 16 bit variable but still come from a 32 bit variable. – Support Ukraine May 16 '16 at 14:44
  • A "32-bit system" typically refers to the natural width of the processor. _not_ it addressing capability - which may be much wider or narrower. – chux - Reinstate Monica May 16 '16 at 15:22

3 Answers3

4

Because you used wrong format specifier which invokes undefined behavior.

To print a pointer, you should use %p format specifier and cast the argument to void*. Something like

 printf("%p",(void *)&a);

will do the job.

That said, you should look into the concepts of virtual memory the first thing.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
1

You can also simply answer your assumption about address size by checking the size of any pointer instead of a test variable's address:

printf("%zu\n", sizeof(int*));
printf("%zu\n", sizeof(float*));

Assuming that a byte in all systems equals eight bit, you can see about size of address.

Please see this SO post

Community
  • 1
  • 1
user3078414
  • 1,942
  • 2
  • 16
  • 24
0

To find the highest possible address for (most of) the currently common systems do this:

#include <stdint.h>
#include <stdio.h>

int main(void)
{
  uintptr_t uip = (uintptr_t) -1;
  void * vp = (void*) uip;

  printf("%p\n", vp);
}
alk
  • 69,737
  • 10
  • 105
  • 255