Here, &p gives address of pointer. So, it act as double pointer?
Is it true?
int *p;
p = &p;
printf("%u %u %u ",p, *p, &p);
Here, &p gives address of pointer. So, it act as double pointer?
Is it true?
int *p;
p = &p;
printf("%u %u %u ",p, *p, &p);
It might help if you posted something that will compile.
Code:int i; int *p = &i; // points to the int int **p = &p; // points to the pointer, which in turn points to the int printf("%p %p %p\n", (void*)&i, (void*)p, (void*)(*pp) );
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Certainly, my code complies in VS 2016 without problem.
Salem you have changed the entire code. I never asked for double pointer declaration and initialization (int **p = &p).
int *p;
p = &p;
printf ("%d %d %d", p, &p, *p);
Finely works in Visual Studio 2013 and GCC
You say it works fine, but are you getting any warnings? You're not providing a complete compilable example for us to reference.
For what it's worth, your example is wrong. "p" is a pointer to int, but you're treating it as if it were a pointer to a pointer.
Are you asking if a pointer can point to itself? I can't find anything in the rules that doesn't allow this (though I haven't looked very hard, nor can I find a good reason to do so).
What's even worse is when you try to dereference an uninitialized *p, which is undefined behavior.
Last edited by Matticus; 12-30-2016 at 11:38 PM. Reason: Added Link
Oh really....
I've no idea what your question is, if you keep posting junk like p = &pCode:$ cat main.c #include <stdio.h> int main() { int *p; p = &p; printf ("%d %d %d", p, &p, *p); return 0; } $ gcc -Wall main.c main.c: In function ‘main’: main.c:6:5: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] p = &p; ^ main.c:7:11: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=] printf ("%d %d %d", p, &p, *p); ^ main.c:7:11: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘int **’ [-Wformat=]
There is no such thing in C where T and T* are the same thing.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.