Skip to content

Commit f5dfc21

Browse files
committed
function
1 parent 195b5dc commit f5dfc21

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Function/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Functions in C
2+
3+
#### Functions are blocks of code which are used to perform specific tasks .
4+
#### In C a function needs to be declared before it’s used.
5+
#### Functions have a function definition , function body and a return type.
6+
#### Functions with return type except void needs to return a value at the end.
7+
#### Functions with return type void do not return any value.
8+
#### A recursive function can call itself during the course of execution of a program.
9+
10+
11+
# Example and Syntax
12+
```
13+
int sum (int a, int b){
14+
return a+b;
15+
}
16+
int main(){
17+
printf(“ %d”, sum(5,10));
18+
}
19+
```
20+
```
21+
void myFunction() {
22+
// code to be executed
23+
}
24+
```
25+
# Explained
26+
#### myFunction() is the name of the function
27+
#### int means that the function datatype
28+
#### Inside the function (the body), add code that defines what the function should do
29+
30+
31+
# Call a Function
32+
#### Declared functions are not executed immediately. They are "saved for later use", and will be executed when they are called.
33+
#### To call a function, write the function's name followed by two parentheses () and a semicolon ;
34+
#### In the following example, myFunction() is used to print a text (the action), when it is called:
35+
36+
37+
38+
39+
40+

Function/function.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <stdio.h>
2+
3+
int main(){
4+
// Create a function
5+
void myFunction() {
6+
printf("I just got executed!");
7+
}
8+
// call the function
9+
myFunction(); // call the function
10+
return 0;
11+
}
12+

0 commit comments

Comments
 (0)