关于C ++的一些问题 [英] some questions on C++

查看:71
本文介绍了关于C ++的一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,

我是新手C ++用户;我以前的所有经历都是关于fortran的。

我刚开始学习C和C ++。我的

心中几乎没有问题。我考虑在这里发布我的查询,以便有经验的人可以帮助我。

1.在C使用的每个函数中包括main(),我们使用返回

0" (stroustroup在

函数的情况下更喜欢直接使用变量)。 whta是这个0的重要性?我检查了

返回1并仍然工作正常。那么什么是'返回'0'的意思

声明?

2.作为我在fortran的基础,(我想在C +中有一个有效的理解

+以及),函数做一些代码工作;当你需要

一次又一次地计算某些东西时,或者说主要程序要使用

结果的单独计算时。记住这一点,我没有得到任何虚函数的逻辑,通过efination,**确实

不**将任何值返回到main()。那么为什么地球上的VOID

需要什么功能?


这可能是一个非常原始的问题,但如果
$ b $我会非常高兴你回答他们。

问候

dear friends,
i am a novice C++ user; all my previous experience is with fortran.
newly i started learnning C and C++. and there is few question in my
mind. I consider to post my queries here, so that experienced ppl may
help me.
1. in every function that C uses including main(), we use "return
0" (stroustroup prefers to use the variable directly in case of
functions). whta is the significance of this "0"? i checked with
return 1 and still its working fine. SO WHAT 0 MEANS IN ''RETURN 0''
STATEMENT?
2. As my foundation in fortran,(and i guess a valid understanding in C+
+ as well), function do some work of the the code; say when you need
to calculate something again and again or a seperate calculation whose
result is to be used by the main program. keeping this in mind, i am
not getting any logic of void function, which by efination, **does
not** return any value to the main(). So why on earth the VOID
FUNCTION NEEDED?

this may be very primitive question, but i ll be really greatful if
you ans them.
regards

推荐答案

rudra写道:
rudra wrote:

亲爱的朋友们,

i是新手C ++用户;我以前的所有经历都是关于fortran的。

我刚开始学习C和C ++。我的

心中几乎没有问题。我考虑在这里发布我的查询,以便有经验的人可以帮助我b
帮助我。
dear friends,
i am a novice C++ user; all my previous experience is with fortran.
newly i started learnning C and C++. and there is few question in my
mind. I consider to post my queries here, so that experienced ppl may
help me.



欢迎! Fortran -C和C ++是一个很大的变化。祝你好运

你的努力!

Welcome! Fortran -C and C++ is quite a change. Best of luck to you
in your efforts!


1.在C使用的每个函数中,包括main(),我们使用"返回

0" (stroustroup在

函数的情况下更喜欢直接使用变量)。 whta是这个0的重要性?我检查了

返回1并仍然工作正常。那么什么0意味着返回0

声明?
1. in every function that C uses including main(), we use "return
0" (stroustroup prefers to use the variable directly in case of
functions). whta is the significance of this "0"? i checked with
return 1 and still its working fine. SO WHAT 0 MEANS IN ''RETURN 0''
STATEMENT?



这取决于运行程序的环境。在许多环境中,零值

意味着一切顺利。 (您可以将其视为b $ b为已发生的错误数)。当然,同样多的

环境_ignore_来自''main'的返回值。

It depends on the environment that runs your program. The value zero
in many environments means "everything went OK" (you can think of it
as "the number of errors that has occurred"). Of course, just as many
environments _ignore_ the return value from ''main''.


2.作为我在fortran的基础, (我想在

C ++中也有一个有效的理解),函数做了一些代码工作;当你说b / b
需要反复计算某个东西或单独计算

时,其结果将由主程序使用。记住这一点,

我没有得到任何虚函数的逻辑,通过efination,

**不会向main()返回任何值。那么为什么在地球上需要VOID

功能呢?
2. As my foundation in fortran,(and i guess a valid understanding in
C+ + as well), function do some work of the the code; say when you
need to calculate something again and again or a seperate calculation
whose result is to be used by the main program. keeping this in mind,
i am not getting any logic of void function, which by efination,
**does not** return any value to the main(). So why on earth the VOID
FUNCTION NEEDED?



这是令人厌恶的,我会给你的。但是想想一个函数

返回''void''(非VOID,C ++是区分大小写的),因为

与SUBROUTINE相同。在Fortran。 C ++在FUNCTION和FUNCTION之间没有任何区别。和SUBROUTINE,除了通过

返回值类型。

It''s an abomination, I''ll give you that. But think of a function
that returns ''void'' (Not VOID, C++ is case-sensitive) as having the
same significance as "SUBROUTINE" in Fortran. C++ does not make any
distinction between "FUNCTION" and "SUBROUTINE", except by means of
the return value type.


>

this可能是一个非常原始的问题,但如果

你是他们的话,我会非常感激。

关于
>
this may be very primitive question, but i ll be really greatful if
you ans them.
regards



希望我的答案有所帮助继续问。


V

-

请在通过电子邮件回复时删除资金'A' br />
我没有回复最热门的回复,请不要问

Hope my answers help. Keep asking.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


rudra写道:
rudra wrote:

亲爱的朋友们,

i是一个新手C ++用户;我以前的所有经历都是关于fortran的。

我刚开始学习C和C ++。我的

心中几乎没有问题。我考虑在这里发布我的查询,以便有经验的人可以帮助我。

1.在C使用的每个函数中包括main(),我们使用返回

0" (stroustroup在

函数的情况下更喜欢直接使用变量)。 whta是这个0的重要性?我检查了

返回1并仍然工作正常。那么什么0意味着返回0

声明?
dear friends,
i am a novice C++ user; all my previous experience is with fortran.
newly i started learnning C and C++. and there is few question in my
mind. I consider to post my queries here, so that experienced ppl may
help me.
1. in every function that C uses including main(), we use "return
0" (stroustroup prefers to use the variable directly in case of
functions). whta is the significance of this "0"? i checked with
return 1 and still its working fine. SO WHAT 0 MEANS IN ''RETURN 0''
STATEMENT?



0表示没有从main返回错误,传统上其他任何东西都被解释为某种错误条件。唯一的要求是从main返回的
''int''值。

0 means no error returned from main, anything else is traditionally
interpreted as some kind of error condition. The only requirement is
''int'' value returned from main.


2.作为我在fortran的基础,(我想在C +

+中也有一个有效的理解),函数做一些工作代码;当你需要

一次又一次地计算某些东西时,或者说主要程序要使用

结果的单独计算时。记住这一点,我没有得到任何虚函数的逻辑,通过efination,**确实

不**将任何值返回到main()。那么为什么在地球上需要VOID

功能呢?
2. As my foundation in fortran,(and i guess a valid understanding in C+
+ as well), function do some work of the the code; say when you need
to calculate something again and again or a seperate calculation whose
result is to be used by the main program. keeping this in mind, i am
not getting any logic of void function, which by efination, **does
not** return any value to the main(). So why on earth the VOID
FUNCTION NEEDED?



将void函数视为Fortran中的子例程。

think of void function as ''subroutine'' in Fortran.


>

这可能是一个非常原始的问题,但如果

你将会非常精彩他们。

关于
>
this may be very primitive question, but i ll be really greatful if
you ans them.
regards



Fei

Fei


" Alf P. Steinbach" < al *** @ start.nowrites:
"Alf P. Steinbach" <al***@start.nowrites:

* rudra:
* rudra:

>亲爱的朋友们,
我是新手C ++用户;我以前的所有经历都是关于fortran的。
我刚开始学习C和C ++。
>dear friends,
i am a novice C++ user; all my previous experience is with fortran.
newly i started learnning C and C++.



< snip>

<snip>


在C中它是一个普通函数(尽管在

程序启动时自动调用),而在C ++中它是's特殊功能,(1)

不能被您的代码调用,(2)不必明确

返回结果值。
In C it''s an ordinary function (although called automatically when the
program starts), whereas in C++ it''s a special function that (1)
cannot be called by your code, and (2) doesn''t have to explicitly
return a result value.



微小的一点:从C99开始,主要的显式回报不再需要
(虽然它被认为是不好的样式而省略它) 。


-

Ben。

Tiny point: as of C99 an explicit return from main is no longer
required (though it is considered bad style to omit it).

--
Ben.


这篇关于关于C ++的一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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