[My Question is little weird but it's not right to change it now as it is answered with good explanation but I am Editing it with [Update].......[Update End] tag to avoid confusion to upcoming visitors to my post]
C
#include<stdio.h>
int main()
{
float *q=NULL;
printf("%f\n",q);
}
OUTPUT
0.000000
- In C output is 0.000000
- so here q is float type null pointer or still q is (void *) type null pointer ?
- I feel it is (void *) type.
- so mismatch in format(%f) and argument(void*) invoke undefined behaviour and lead to such error type output
[Update] But you will fill answer to my own Question such stupid Question I asked
basically I am confused that I feel I have to print something float type or void type but point is I am printing address and so it just foolish to use %f to use to print address.
Obviously q is float type pointer only what I feel is totally wrong
generally we use %u to print address of any type of variable(int,char,float) but for pointer we should use %p
[Update End]
C++
#include<iostream>
int main()
{
float *q=nullptr;
std::cout<<q;
}
OUTPUT
0
- In C++ give output 0
- I think it's fine as it give address of 1st memory block as pointing to nothing
- and if q is nullptr_t type then C++11 should give ambugity error means here q is float type nullptr.
[Update]
The C and C++ standards both specify that a null pointer constant compares equal to zero - they say nothing about what is at that address.
obviously q is float type nullptr only
[Update End]
So if my both assumptions are correct then why in C++ nullptr changing it's type to float type from nullptr_t but in C NULL is not changing it's type from (void ) to (float) ?
[Update]
My first assumption in 1st example of C that q is (void*) type is already wrong and 2nd Assumption that in 2nd ex. of C++ that q is nullptr_t is also wrong.
So Summarize all here
I am trying to compare that this is happening in C and this is happening in c++ and I feel these things are contradict to each other
but in reality while in C I am using %f to print address of pointer that's first mistake. In C++ code all I think is all right except One thing that it is wrong to assume that null pointer points to 1st block of memory which is 0th as it is not specify in c standard it just say that nullptr constant compares to 0 when evaluate.
so tons of mistake in question only so it is not proper question
[Update End]