-3
我想創建一個鏈表,但每當我嘗試將數據分配給結構中的數據字段時,我會得到分段錯誤..Plz幫助?通過指針賦值給結構域時,分段錯誤?
struct Node
{
int data;
Node* next;
};
int main()
{
ios_base::sync_with_stdio(false);
Node* start=NULL;
Node* prev=NULL;
int N,Q,L,M,R,x;
cin>>N>>Q;
cin >> x;
start->data = x; // The Line where i get error
start->next=NULL;
prev = start;
return 0;
}
您試圖從NULL指針訪問內存位置,因爲'Node * start = NULL;' –
您需要[好書](http://stackoverflow.com/questions/388242/the-definitive-c -book引導和列表)。你絕對不需要'ios_base :: sync_with_stdio(false);'。 – molbdnilo
這不是整個代碼,它只是一個部分... ios_base :: sync_with_stdio(false);這是上下文所要求的。無論如何,我試圖聲明這些指針後聲明的結構沒有初始化爲空,同樣的錯誤仍然 –