So I've been playing around with linked lists, and since I like to see the data I'm working with I tried to make a print function that would print out all the data in the list.
I distilled the problem into simplest runnable code I could here,
Code:
#include <iostream>
using namespace std;
struct stuff
{
int data;
};
void printStructPointer(stuff *s)
{
cout << s->data << endl; // and this is what kills the program
}
int main()
{
stuff *p_stuff;
p_stuff->data = 10;
printStructPointer(p_stuff);
return 0;
}
The program crashes. I'm confused because I'm able to change data member values when passing in the struct by pointer, so there's no problem accessing the data. But as soon as I use cout on a member variable the program crashes. Is there a limitation with cout that I don't know of, or am I missing something obvious?