什么用途无效? [英] What use is void?
问题描述
你好,我在想,如果你写的话会有什么不同吗
void foo(int x)
{
/ *在这里插入代码* /
}
或
foo(int x)
{
/ *在此处插入代码* /
}
有什么区别?两种方式的功能都不会返回任何东西,
对吗?写空虚有什么意义?它仅仅是一个美容功能吗?
-
Ian Tuomi
Jyv?skyl ?,芬兰
GCS d-s +:a --- C ++> $ L +> +++ $ E- W + N +!o> + w ---
!O-!M-t +!5!X R + tv-b ++ DI +!DG e-> +++ h!
< blockquote> L +> +++
E-W + N +!o> + w ---
!O-!M-t +!5! X R + tv-b ++ DI +!DG e-> +++ h!
Ian Tuomi写道
你好,我想知道,如果你写的话会有什么不同
void foo(int x)
/ * insert code这里* /
}
foo(int x)
{
/ *在这里插入代码* /
}
有什么区别?两种方式的功能都不会返回任何东西,对吧?写空虚有什么意义?它只是一个美化特征吗?
绝对不是。如果省略函数声明中的返回类型,则
返回类型默认为int,所以
foo(int x)
实际上是
int foo(int x)
void类型用作返回的类型通过不产生
值的函数。
---
用户
>
Hello, I was wondering, does it make any difference if you write
void foo(int x)
{
/* insert code here */
}
or
foo(int x)
{
/* insert code here */
}
What is the difference?? Both ways the function wont return anything,
right? What is the point in writing void? Is it merely a cosmetic feature?
--
Ian Tuomi
Jyv?skyl?, Finland
GCS d- s+: a--- C++>$ L+>+++$ E- W+ N+ !o>+ w---
!O- !M- t+ !5 !X R+ tv- b++ DI+ !D G e->+++ h!
L+>+++
E- W+ N+ !o>+ w---
!O- !M- t+ !5 !X R+ tv- b++ DI+ !D G e->+++ h!
Ian Tuomi wrote
Hello, I was wondering, does it make any difference if you write
void foo(int x)
{
/* insert code here */
}
or
foo(int x)
{
/* insert code here */
}
What is the difference?? Both ways the function wont return anything,
right? What is the point in writing void? Is it merely a cosmetic feature?
Absolutely not. If you omit a return type from a function declaration, the
return type defaults to `int'', so
foo(int x)
is actually
int foo(int x)
The void type is used as the type returned by functions that generate no
value.
---
user
这篇关于什么用途无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!