Why am I getting segmentation fault with this code?
#include<stdio.h>
typedef struct
{
int val;
} DEVICE;
main()
{
DEVICE *dev_ptr;
dev_ptr->val = 21;
printf(" %d ",dev_ptr->val);
}
I know the correct way of assigning the values. For that we need to add these lines
DEVICE simple;
dev_ptr = &simple;
simple.val = 21;
but I want to know what is wrong with previous code ?