K
K
kolomiec_artiom2018-06-27 17:05:56
C++ / C#
kolomiec_artiom, 2018-06-27 17:05:56

How to display the address of an object in C?

Good afternoon!
I'm trying to display the address of an object:

#include <stdio.h>

int main(void)
{
    int i = 034534;
    char h = 'h';

    printf ("i=%d, &i=%n \n", i, &i);
    printf ("h=%c, &i=%p \n", h, &h);
    return 0;
}

The address of an object of type "char" is displayed, and for int it says: Invalid parameter passed to C runtime function.
How to display in C language the address of an int object?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
15432, 2018-06-27
@kolomiec_artiom

Why are you using %n?
You also need %p or at least %x

R
res2001, 2018-06-27
@res2001

#include <inttypes.h>
printf("%" PRIuPTR, &i);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question