C语言中的形实参双向传递该怎么做?
C语言中规定的是实参-〉形参的单向传递方式,这种方式有些时候很不方便,我在一本书上看到说用指针的方法可以解决这个问题,大虾们能否说说怎么样实现双向传递呢?比如这个题目:
编写一个void InitStack(Stack *s)的栈的初始化函数,功能是建立由s指向的一个栈,并初始化栈顶,栈底指针和栈的长度。其中Stack是定义的一个描述栈的结构体,将这个结构体看作一个对象,s是指向这个对象的指针。因为函数的返回值为void型,所以必须使得在函数中所作的初始化能够传递到主函数中,即双向传递。
我试着写了一个,但还是没有实现双向传递,迷茫中,请大虾赐教
栈空间定义:
#define STACK_INIT_SIZE 10 //initial sizes
#define STACK_INCREMENT 2 //size-increment
结构体定义:
struct stack //define the stack struction
{
int * base; //base pointer,which point the base of the stack
int * top; //top pointer,whick point the top of the stack
int stackSize; //the size of the stack
};