Suppose on my platform sizeof(int)==sizeof(void*)
and I have this code:
printf( \"%p\", rand() );
Will this be undefined behavior
%p is just a output format specification for printf. It doesn't need to dereference or validate the pointer in any way, although some compilers issue a warning if the type is not a pointer:
int main(void)
{
int t = 5;
printf("%p\n", t);
}
Compilation warning:
warning: format ‘%p’ expects argument of type ‘void*’, but argument 2 has type ‘int’ [-Wformat]
Outputs:
0x5