同一个程序在codeblocks编译成功在VS2015失败是为什么呢

 using namespace std;
#include<iostream>
struct node
{
    int data;
    struct node *next;
};
int main()
{
    struct node *head, *p, *t, *q;
    int  a, n, i;
    cin >> n;
    head = NULL;
    for (i = 1; i <= n; i++)
    {
        cin >> a;
        p = new node;
        p->data = a;
        p->next = NULL;
        if (head == NULL)
            head = p;
        else
            q->next = p;
        q = p;
    }
    t = head;
    while (t != NULL)
    {
        cout << t->data<<' ';
        t = t ->next;
    }
    return 0;
}

![图片说明](https://img-ask.csdn.net/upload/201612/28/1482919034_643653.png)图片说明

q->next = p;
q未初始化,所有->next未知。

代码没什么问题,刚刚在我的电脑上测试了下,可以运行。 估计是你哪里复制出问题了。