为了账号安全,请及时绑定邮箱和手机立即绑定

数据结构 c语言 作用域问题

数据结构 c语言 作用域问题

问题用//标出来了,同样的语句为什么放入循环结果就完全不同了?#include <stdio.h>#include <stdlib.h>#define OK 1#define NO 0int nn=0;typedef struct Node{    int data;    struct Node *next;}Node,*Linkstackptr;typedef struct{    Linkstackptr top;    int count;}Linkstack;Linkstackptr Createstacktail(Linkstack *S,int n)   {    Linkstackptr r,p;    S->count=0;    Linkstackptr *L;    *L=(Node*)malloc(sizeof(Node));    (*L)->data=++nn;(*L)->next=NULL;    r=*L;    S->top=*L; S->count++;    printf("%d\n",(*L)->data);          //    int j;    for(j=1;j<n;j++)    {   printf("%d\n",(*L)->data);       //        p=(Node*)malloc(sizeof(Node));        p->data=++nn;        p->next=NULL;        r->next=p;        r=p;        S->count++;    }    //printf("%d\n",(*L)->data);    //printf("%d\n",(*L)->next);    return *L;}void main(){    Linkstackptr first;    Linkstack S;    first=Createstacktail(&S,3);    //Showlist(first);    //printf("%d\n",S.count);    //Showlist(first);}
查看完整描述

1 回答

?
江户川乱折腾

TA贡献1851条经验 获得超5个赞

在学数据结构 可以去学堂在线上课,选择这堂课的资料学习,丢掉你现在手上的书,这代码风格,现代编译器一堆报错

查看完整回答
反对 回复 2018-10-29
?
临摹微笑

TA贡献1982条经验 获得超2个赞

Code style 挺醉人的……

$ gcc linkstack.c -o link && ./link

[1]    6174 segmentation fault  ./link


$ gcc --version

gcc (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1 20160904

Copyright (C) 2015 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


查看完整回答
反对 回复 2018-10-29
  • 1 回答
  • 0 关注
  • 1087 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信