Return (value) discussion ...... (Message Type: chat record: Message Group: Group/record)

Source: Internet
Author: User

User: 404082727 (the best way to do things)

========================================================== ============
Message Group: Group/record (51)
========================================================== ============
Message Type: Chat History
========================================================== ============

 

12:36:53/K rain (9)
Int test (int I ){
I ++;
}

Int main (void ){
Int I = 0;
For (I = 0; I <10; I ++ ){
Test (I );
}
}

Is it meaningful?
 

12:42:15 ()
Meaningless

-12-12-5 12:42:20 on the road (7)
Other errors

-12-12-5 12:42:46 on the road (7)
Return 0;
The main function has no return value.

12:43:13 ()
Neither does test.

2004-12-05 12:48:54 Bucha ()
Neglected. [:-|] However, this is only because someone asks what the optimized code looks like and does not make any sense.

12:55:10/Kun meteor shower (4)
Haha

12:56:01 rain (16)
I would like to discuss: What is the significance of the primary function returning 0?

-12-12-5 12:56:46 on the road (4)
The system can know that the program has ended normally.

12:57:01 rain (1)
Isn't the same as returning 1 to end the program normally?

12:57:27 rain)
No difference.

12:58:16 floating)
I'm afraid no one has made it clear, right? Sad

2004-12-05 12:58:35 Bu
In most cases, it doesn't matter. However, the system can know from the returned value whether your program has an error. Generally, return 0 indicates no. A non-zero value indicates an error code. UNIX habits

13:00:04 ()
I'm a bit confused. I don't pay attention to this.

13:00:17
This way...
I think... if there is a real error in the program, it will be over if it is not executed until return 0.

13:02:12 Buch)
However, it does not rule out the possibility of final appearance. Generally, 0 is returned at the end, indicating that it is normal. Otherwise, how do other programs know whether you are returning at the end or in the middle?

13:02:52 Buch)
For example, in DOS, the returned value exists in errorlevel.

13:05:15 floating)
If an error occurs during execution and an unexpected termination occurs, how does the system know this error?

13:06:14 buchi)
The simplest is to return a non-zero value. Countless UNIX programs do this.

13:09:33 floating)
I have some questions:
Return 0
Return 1
It is the last sentence of the program. no matter whether the program ends normally or abnormally, all the execution processes have been executed. Now, I want to tell the system What is the purpose? What if the system knows?

13:10:58 floating rain 6)
Buchi automata brother?

13:10:59 Buch
This is determined by people. If a program considers 1 as an error, it can handle it accordingly.

2004-12-05 13:11:19 Laz
It only indicates that the program is successfully executed.
The system needs to know this

13:12:12 Buch)
Even if you don't need to know what the system requires, you have to decide.

13:12:36 floating)
I don't know how to set this stuff.

13:13:02 rain)
Maybe UNIX works, but not windows?

13:13:45 BUC)
Depends on your needs. It works in windows, but it seems that few people are using it.

13:14:15 floating)
I strongly Want To Talk About buchi Automata

13:14:38 buc3)
I don't do programming in windows, so I don't know.

13:16:08 rain
Disappointing ing... let's talk about how to handle non-zero return in Unix. You can also understand the principle.

13:17:35 BUC)
As for UNIX, I have already said it. For example. For example, your program kills a process: killprocess. You can call the following command in shell:
V = killprocess
If (V = 1) echo successful else echo failed

13:18:55 BUC
That is to say, the programmer determines what numbers represent. Nothing to say

13:19:50 rain)
Understanding...

13:21:30 floating)
V = killprocess
If (V = 1) echo successful else echo failed
File: // call a program. It is no different from calling a function in the program.
File: // but does this shell look like a programming environment?

13:21:50 BUC)
Equivalent to DOS window

13:22:56 floating)
Equivalent to DOS window
----------------
In it, input the programming commands and observe the program results?

13:23:01/K
The main function returns an integer value to the system caller. The system cannot ignore this returned value, so "Void main ()" is invalid in C ++ and C.

13:23:43 bu)
The system can ignore this value. I don't know what this book says.

13:23:46 rain
The main function returns an integer value to the system caller. The system cannot ignore this returned value, so "Void main ()" is invalid in C ++ and C.
---------------------------
Void main ()
I remember writing it like this.

13:23:54/Ku)
Standard,

13:24:22 buchi)
What standards?

13:24:34/Kun stream
In addition, it should be noted that the type declaration of the main function is not allowed to be omitted in Iso c ++ and c99 standards, and is not applicable to c89 and arm C ++ standards.

2004-12-05 13:25:04/Kun meteor
The type declaration of the main function cannot be omitted.

There is a return value.

13:25:40 buchi
Well, in C ++, yes. However, it is irrelevant whether the system can ignore the returned value. The language is the language, and the system is the system.

2004-12-05 13:27:02/Kun meteor
Haha

13:27:13/Kun stream
Cannot understand, ding ,,,,,,,,

13:28:26
I just remembered a question:
Return 0;
Return 1;
No matter what is returned .. it indicates normal exit or abnormal exit. We can see an explicit exit statement, and the error that will actually lead to abnormal exit of the program is not expected by the programmer, so I certainly won't write a return statement to put it there, and return an error to the System

13:28:56 buchi Au
In fact, it is easy to understand: the C ++ standard defines that the main function must return an int, but this is only the syntax. Isn't it necessary for other programs to process the returned value?

13:30:11
How can the system capture this error at this time?

13:30:20 buchi Au
Not necessarily. I can try {...} catch (exception e) {return 1 ;}. This is much more done. Besides, do not narrowly understand system errors. Not all errors cause the program to exit unexpectedly.

2004-12-05 13:31:40 buchi aut
If the program exits unexpectedly, the system can only get an error message without specific meaning. It indicates that your program is not compiled properly [: d]

13:34:16
Haha, when the error is not serious enough to exit the program directly
Can I exit the program with exception handling?
If this error is serious, you can only say that my program is not well written.
-------------------
Does this mean? Sadsadsad

13:35:17 buchi Au
An exception is just an example. There are no language-level exceptions in C. The program should try to handle various exceptions.

13:36:55 rain time/
Benefits...

13:37:43
I knew my eldest brother was a hard-handed man.

13:37:55
Go to dinner first

2004-12-05 13:39:08 buchi autom
[: $] Award received

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.