From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/SYNTAX/return.html | 134 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 reference/C/SYNTAX/return.html (limited to 'reference/C/SYNTAX/return.html') diff --git a/reference/C/SYNTAX/return.html b/reference/C/SYNTAX/return.html new file mode 100644 index 0000000..68a9c2c --- /dev/null +++ b/reference/C/SYNTAX/return.html @@ -0,0 +1,134 @@ +The return statement + + + + +
+
+

The return statement

+
+
+

+return will return a value from a function to its caller. +The value returned is +the result of an expression. +

+


+As an Example this will print 7 + +

+ + + + +
+
+
+        int func(void);
+
+	main()
+ 	{
+	   printf("%d \n", func());
+        }
+
+        int func(void)
+        {
+           return 7;
+	}
+
+
+

+ +What ever follows the return statement will be evaluated as +an expression. So, to be consistant you could place brackets around +the return value. + +

+ + + + +
+
+
+        return(7);
+
+
+

+Or you could evaluate a formula on the statement: + +

+ + + + +
+
+
+	return (Count-1);
+
+
+

+Finally, if the function returns a void +the return statement is not required, but maybe needed to +leave a function before the end of the function block. Here +is an example. + +

+ + + + +
+
+
+	void CheckDate(int)
+
+	main()
+	{
+	  CheckDate(40)
+        }
+
+	void CheckDate(int Month)
+	{
+	  if (Month > 31)
+	  {
+	    return;
+	  }
+
+	  puts("Month is valid");
+        }
+
+
+

+


+

See also:

+The exit function. + + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + -- cgit v1.2.3-54-g00ecf