函数参数入/出栈顺序

1          入栈

1.1         入栈内容

1.1.1    函数参数

1.1.2    函数返回地址

1.1.3    …

1.2         参数入栈顺序

1.2.1    参数从右到左入栈

1.2.2    原因

1.2.2.1   支持可变长参数

1.2.2.2   C语言中调用约定所采用的方式

 


1.3         反汇编检查

1.3.1    如下图,进栈的顺序是0x12c(300),0xc8(200), 0x64(100)。

 

 

2          出栈

2.1         …


C2660: “Push”: 函数不接受 2 个参数;C2660: “StackEmpty”: 函数不接受 0 个参数;error C2562: “main”:“void”函数返回值 //顺序基本运算算法 #include <stdio.h> #include <malloc.h> #define MaxSize 100 typedef char ElemType; typedef struct { ElemType data[MaxSize]; int top; //指针 } SqStack; //顺序类型 //创建顺序InitStack void InitStack(SqStack * &s){ s=(SqStack *)malloc(sizeof(SqStack)); s->top=-1; } //判断顺序是否为空StackEmpty bool StackEmpty(SqStack * s){ return s->top == -1; //return true; } //Push bool Push_1(SqStack * s){ return s->top==-1; } void Push(SqStack * s) { if(s->top==-1){ printf("顺序为空\n"); } else{ printf("顺序不为空\n"); } } //出栈Pop bool Pop(SqStack * &s, ElemType e){ if (s->top == MaxSize - 1){ printf("顺序已满,无法\n"); } s->top++; s->data[s->top] = e; printf("元素%d完成\n",e); return true; } //按顺序输出整个顺序 void PrintStack(SqStack * s) { if (StackEmpty(s)) { printf("顺序为空\n"); return; } for (int i = 0; i <= s->top; i++) { printf("%d ", s->data[i]); } printf("\n"); } //销毁顺序 void DestroyStack(SqStack * &s) { free(s); s = NULL; } //提高性项目:基于的特性,实现十进制转八进制的代码实现。 //步骤: //①定义顺序 //②使用辗转相除法将该十进制数除以八,将余数依次 //③将中元素依次出栈 //④销毁顺序 void DecToOct(int num) { SqStack *s = NULL; InitStack(s); while (num > 0) { Push(s, num % 8); num /= 8; } printf("十进制 %d 转换为八进制是: ", num); ElemType e; while (Pop(s, e)) { printf("%d", e); } printf("\n"); DestroyStack(s); } void main(){ //顺序的初始化InitStack SqStack *s=NULL; InitStack(s); printf("顺序表地址为%p\n",s); //判断顺序是否为空StackEmpty bool as; as=StackEmpty(); if(as==true){ printf("as的值为true"); } //Push Push(s); //出栈Pop ElemType e=10; Pop(s,e); printf("顶元素为%d\n",s->data[s->top]); //按顺序输出整个顺序 PrintStack(s); //销毁顺序 DestroyStack(s); //提高性项目:基于的特性,实现十进制转八进制的代码实现。 DecToOct(2025269509); return 0; }
10-27
C2660:“StackEmpty”: 函数不接受 1 个参数;C2100:非法的间接寻址;C2664: InitStack”: 不能将参数 1 从“SqStack”转换为“SqStack *&”;C2660: “Push”: 函数不接受 2 个参数; C2664: “Pop”: 不能将参数 1 从“SqStack *”转换为“SqStack *&”;C1903:无法从以前的错误中恢复;正在停止编译//顺序基本运算算法 #include <stdio.h> #include <malloc.h> #define MaxSize 100 typedef char ElemType; typedef struct { ElemType data[MaxSize]; int top; //指针 } SqStack; //顺序类型 //创建顺序InitStack void InitStack(SqStack * &s){ s=(SqStack *)malloc(sizeof(SqStack)); s->top=-1; } //判断顺序是否为空StackEmpty bool StackEmpty(){ return true; } //Push bool Push_1(SqStack * s){ return s->top==-1; } void Push(SqStack * s) { if(s->top==-1){ printf("顺序为空\n"); } else{ printf("顺序不为空\n"); } } //出栈Pop bool Pop(SqStack * &s, ElemType e){ if (s->top == MaxSize - 1){ printf("顺序已满,无法\n"); } s->top++; s->data[s->top] = e; printf("元素%d完成\n",e); return true; } //按顺序输出整个顺序 void PrintStack(SqStack * s) { if (StackEmpty(s)) { printf("顺序为空\n"); return; } for (int i = 0; i <= s->top; i++) { printf("%d ", s->data[i]); } printf("\n"); } //销毁顺序 void DestroyStack(SqStack * &s) { free(s); s = NULL; } //提高性项目:基于的特性,实现十进制转八进制的代码实现。 //步骤: //①定义顺序 //②使用辗转相除法将该十进制数除以八,将余数依次 //③将中元素依次出栈 //④销毁顺序 void DecToOct(int num) { SqStack s; InitStack(&s); while (num > 0) { Push(&s, num % 8); num /= 8; } printf("十进制 %d 转换为八进制是: ", num); ElemType e; while (Pop(&s, e)) { printf("%d", e); } printf("\n"); DestroyStack(&s); } void main(){ //顺序的初始化InitStack SqStack *s=NULL; InitStack(s); printf("顺序表地址为%p\n",s); //判断顺序是否为空StackEmpty bool as; as=StackEmpty(); if(as==true){ printf("as的值为true"); } //Push Push(s); //出栈Pop ElemType e=10; Pop(s,e); printf("顶元素为%d\n",s->data[s->top]); //按顺序输出整个顺序 PrintStack(s); //销毁顺序 DestroyStack(s); //提高性项目:基于的特性,实现十进制转八进制的代码实现。 DecToOct(2025269509); return 0; }
10-27
//顺序基本运算算法 #include <stdio.h> #include <malloc.h> #define MaxSize 100 typedef char ElemType; typedef struct { ElemType data[MaxSize]; int top; //指针 } SqStack; //顺序类型 //创建顺序InitStack void InitStack(SqStack * &s){ s=(SqStack *)malloc(sizeof(SqStack)); s->top=-1; } //判断顺序是否为空StackEmpty bool StackEmpty(){ return true; } //Push bool Push_1(SqStack * s){ return s->top==-1; } void Push(SqStack * s) { if(s->top==-1){ printf("顺序为空\n"); } else{ printf("顺序不为空\n"); } } //出栈Pop bool Pop(SqStack * &s, ElemType e){ if (s->top == MaxSize - 1){ printf("顺序已满,无法\n"); } s->top++; s->data[s->top] = e; printf("元素%d完成\n",e); return true; } //按顺序输出整个顺序 void PrintStack(SqStack * s) { if (StackEmpty(s)) { printf("顺序为空\n"); return; } for (int i = 0; i <= s->top; i++) { printf("%d ", s->data[i]); } printf("\n"); } //销毁顺序 void DestroyStack(SqStack * &s) { free(s); s = NULL; } //提高性项目:基于的特性,实现十进制转八进制的代码实现。 //步骤: //①定义顺序 //②使用辗转相除法将该十进制数除以八,将余数依次 //③将中元素依次出栈 //④销毁顺序 void DecToOct(int num) { SqStack s; InitStack(*s); while (num > 0) { Push(&s, num % 8); num /= 8; } printf("十进制 %d 转换为八进制是: ", num); ElemType e; while (Pop(&s, e)) { printf("%d", e); } printf("\n"); DestroyStack(&s); } void main(){ //顺序的初始化InitStack SqStack *s=NULL; InitStack(s); printf("顺序表地址为%p\n",s); //判断顺序是否为空StackEmpty bool as; as=StackEmpty(); if(as==true){ printf("as的值为true"); } //Push Push(s); //出栈Pop ElemType e=10; Pop(s,e); printf("顶元素为%d\n",s->data[s->top]); //按顺序输出整个顺序 PrintStack(s); //销毁顺序 DestroyStack(s); //提高性项目:基于的特性,实现十进制转八进制的代码实现。 DecToOct(2025269509); return 0; }
最新发布
10-27
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值