如何在函数参数中将结构指针变量设置为默认值NULL? [英] How do I set a structure pointer variable to default value NULL in a function parameter?

查看:233
本文介绍了如何在函数参数中将结构指针变量设置为默认值NULL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

struct queue{
    int value;
    struct queue *tlink;
    struct queue *blink;
};

typedef struct queue* Q;

void enqueue(Q top, int val, Q bottom=NULL);



错误:



error:

expected ‘;’, ‘,’ or ‘)’ before ‘=’ token
void enqueue(Q top, int val, Q bottom=NULL);



我尝试过的事情:

我正在尝试将结构指针变量初始化为函数参数中的默认值NULL. (默认参数)



What I have tried:

I am trying to initialise a structure pointer variable to default value NULL in function parameter. (Default parameter)

推荐答案

C没有默认参数的概念,因此您几乎不能这样做.


(请问,这是骗人的孩子,但它非常复杂和混乱: C默认参数-堆栈溢出 [ ^ ] -请参阅BK的解决方案,即TBH比维护POV最初的问题要差.)
C doesn''t have any concept of default parameters, so you pretty much can''t do that.


(Which is a lie-to-children, becuase you can, but it''s horribly complicated and messy: C default arguments - Stack Overflow[^] - see BK''s solution, which TBH is worse than the original problem from a maintenance POV).


这篇关于如何在函数参数中将结构指针变量设置为默认值NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆