Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ashok Kumar, Bharath
so2021
Commits
e5676f2d
Commit
e5676f2d
authored
Apr 21, 2021
by
Praetorius, Simon
Browse files
Update the section about functions
parent
eb58bd9c
Changes
2
Hide whitespace changes
Inline
Side-by-side
presentation/_includes/arithmetic-operators.md
View file @
e5676f2d
...
...
@@ -186,6 +186,8 @@ b = (x == 2 || y == 3 || z == 4);
b
=
(
x
!=
0
&&
y
/
x
>
1
);
```
See https://en.cppreference.com/w/cpp/language/eval_order for details.
---
# Relational and Logical Operators
...
...
@@ -233,6 +235,8 @@ bool b = std::abs(x-y) <= eps * std::abs(x+y) * ulp || std::abs(x-y) < min;
> .h3[Remark:] Mathematical functions often have an accuracy of a few ULPs, see
> [Errors-in-Math-Functions](https://www.gnu.org/software/libc/manual/html_node/Errors-in-Math-Functions.html)
See
[
boost/math_toolkit/float_comparison
](
https://www.boost.org/doc/libs/1_76_0/libs/math/doc/html/math_toolkit/float_comparison.html
)
for details.
---
# Precedence and Associativity of Operators
...
...
presentation/_includes/functions.md
View file @
e5676f2d
...
...
@@ -7,6 +7,26 @@ class: center, middle
## Function Declaration/Definition
The declaration of a function in C++ follows
```
c++
<
return_type
>
<
function_name
>
(
<
argument_list
>
...);
// C-style, or
```
-
When a function does not return a result, then the return type is
`void`
.
-
To return a value from a function, C++ provides the keyword
`return`
.
```
c++
double
square
(
double
const
x
)
void
print
()
{
{
return
x
*
x
;
std
::
cout
<<
"Hello World"
<<
std
::
endl
;
}
}
```
---
# Functions
## Function Declaration/Definition
The declaration of a function in C++ follows
```
c++
<
return_type
>
<
function_name
>
(
<
argument_list
>
...);
// C-style, or
auto
<
function_name
>
(
<
argument_list
>
...)
->
<
return_type
>
;
// Since [C++11]
...
...
@@ -16,15 +36,15 @@ auto <function_name> (<argument_list>...) -> <return_type>; // Since [C++11]
-
To return a value from a function, C++ provides the keyword
`return`
.
```
c++
double
square
(
double
const
x
)
{
return
x
*
x
;
}
double
square
(
double
const
x
)
void
print
()
{
{
return
x
*
x
;
std
::
cout
<<
"Hello World"
<<
std
::
endl
;
}
}
// or
auto
square2
(
double
const
x
)
->
double
{
return
x
*
x
;
}
auto
square2
(
double
const
x
)
->
double
auto
print
()
->
void
{
{
return
x
*
x
;
std
::
cout
<<
"Hello World"
<<
std
::
endl
;
}
}
```
---
...
...
@@ -43,15 +63,15 @@ auto <function_name> (<argument_list>...); // Since [C++14]
-
To return a value from a function, C++ provides the keyword
`return`
.
```
c++
double
square
(
double
const
x
)
{
return
x
*
x
;
}
double
square
(
double
const
x
)
void
print
()
{
{
return
x
*
x
;
std
::
cout
<<
"Hello World"
<<
std
::
endl
;
}
}
// or
auto
square2
(
double
const
x
)
{
return
x
*
x
;
/
/
-> double
}
auto
square2
(
double
const
x
)
auto
print
()
{
{
return
x
*
x
;
/
*
-> double
*/
std
::
cout
<<
"Hello World"
<<
std
::
endl
;
}
}
```
---
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment