In the following program, ptr points to uninitialized variable x. Before printing ptr, I have assigned 10 to ptr and print it.
#include <stdio.h>
int main()
{
int *ptr;
int x;
ptr = &x;
*ptr = 10;
printf(" x = %d\n", x);
printf(" *ptr = %d\n", *ptr);
}
Both ptr and x print the correct value. But, I have doubt, Is it defined behavior?
ptr, i have assigned10toptrand dereferenced it." ? Assigning10to*ptr(notptris dereferencing. You dereference it before you dereference it?