Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
22 views
8 pages
C 31
Uploaded by
hlemorvan
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save c31 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
22 views
8 pages
C 31
Uploaded by
hlemorvan
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save c31 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 8
Search
Fullscreen
‘11212028 20.49 (C Funetion Parameters 3 w Tutorialsy —Exercisesw Servicese§ QO Log in schools C Function Parameters [crv] Looe | Parameters and Arguments Information can be passed to functions as a parameter. Parameters act as variables inside the function. Parameters are specified after the function name, inside the parentheses. You can add as many parameters as you want, just separate them with a comma: Syntax returnType functionName(parameter1, parameter2, parameter3) { // code to be executed The following function that takes a string of characters with name as parameter. When the function is called, we pass along a name, which is used inside the function to print "Hello" and the name of each person. Example void myFunction(char name{]) { jello %s\n", name) ; printf(” ? int main() { nitpsdlwwwavdschools.comiele_funetions_parameters.php ve‘11212028 20.49 (C Funetion Parameters 3 w Tutorialsy —Exercisesw Servicese§ QO Log in schools // Hello Liam // Hello Jenny // Hello Anja When a parameter is passed to the function, it is called an argument. So, from the example above: name is a parameter, while Lian, Jenny and Anja are arguments. Multiple Parameters Inside the function, you can add as many parameters as you want: Example void myFunction(char name[], int age) { printf("Hello %s. You are %d years old.\n", name, age); ? int main() { myFunction("Liam", 3); myFunction("Jenny", 14); myFunction("Anja", 30); return 0; // Hello Liam. You are 3 years old. // Hello Jenny. You are 14 years old. // Hello Anja. You are 30 years old. nitpsdimwwavdschools comiele_funetions_parameters.ohp 28‘11212028 20.49 (C Funetion Parameters 3 w Tutorialsy —Exercisesw Servicese§ QO Log in schools Note that when you are working with multiple parameters, the function call must have the same number of arguments as there are parameters, and the arguments must be passed in the same order. Pass Arrays as Function Parameters You can also pass arrays to a function: Example void myFunction(int myNumbers[5]) { for (int i=; i < 55 itt) { printf(“%d\n", myNumbers[i])5 int main() { int myNumbers[S] = (10, 2, 30, 40, 50}; myFunction(myNumbers) ; return 0; Example Explained The function ( myFunction ) takes an array as its parameter (int myNumbers[5] ), and loops through the array elements with the for loop. When the function is called inside main() , we pass along the myNumbers array, which outputs the array elements. nitpsdimwwavdschools comiele_funetions_parameters.ohp 38‘11212028 20.49 (C Funetion Parameters 3 w Tutorialsy —Exercisesw Servicese§ QO Log in schools Return Values The void keyword, used in the previous examples, indicates that the function should not return a value. If you want the function to return a value, you can use a data type (such as int or float, etc.) instead of void, and use the return keyword inside the function: Example int myFunction(int x) { return 5 + x; ? int main() { printf("Result is: %d", myFunction(3))5 return @; // Outputs 8 (5 + 3) This example returns the sum of a function with two parameters: Example int myFunction(int x, int y) { return x + y3 > int main() { printf("Result is: %d", myFunction(5, 3)); return 03 nitpsdlwwwavdschools.comiele_funetions_parameters.php 48‘11212028 20.49 (C Funetion Parameters 3 w Tutorialsy —Exercisesw Servicese§ QO Log in schools You can also store the result in a variable: Example int myFunction(int x, int y) { return x + y5 int main() { int result = myFunction(s, 3); printf("Result is = %d", result); return 0; ? // Outputs 8 (5 + 3) Real-Life Example To demonstrate a practical example of using functions, let's create a program that converts a value from fahrenheit to celsius: Example // Function to convert Fahrenheit to Celsius float toCelsius(float fahrenheit) { return (5.0 / 9.8) * (fahrenheit - 32.0); int main() { // Set a fahrenheit value nitpsdlwwwavdschools.comiele_funetions_parameters.php 58‘11212028 20.49 ¢ Function Parameters 3 w Tutorials» Exercisese Servieesey§ QO SignUp Login schools = CSS JAVASCRIPT SQL. PYTHON = JAVA. PHP-—«S HOWTO— W3.CSS_— // Print the fahrenheit value printf("Fahrenheit: %.2f\n", f_value); // Print the result printf("Convert Fahrenheit to Celsius: %.2f\n", result); return 3 Try it Yourself » Log in to track progress J & Earn Your Certificate Today And Unlock Tomorrow's Opportunities! Celt SeTacls) Don't let hesitation hold you back. a Theest time to starts now, COLOR PICKER htipsulmaew.wdechools.comicle.functions_parameters.pha oe‘11212028 20.49 w schools Tutorials~ Exercises = CSS JAVASCRIPT = SQL ¢ Function Parameters Sevicesy Q @O Sign Up. PYTHON JAVA PHP = HOWTO w schools SPACES GET CERTIFIED Top Tutorials HTML Tutorial SS Tutorial JavaScript Tutorial How To Tutorial ‘SQL Tutorial Python Tutorial Wa.cSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial cH Tutorial Query Tutorial Top References HTML Reference CSS Reference JavaScript Reference ‘SQL Reference Python Reference W3.CSS Reference Bootstrap Reference PHP Reference HTML Colors Java Reference ‘Angular Reference JQuery Reference Top Examples HTML Examples CSS Examples JavaScript Examples How To Examples SQL Examples Python Examples W3.CSS Examples Bootstrap Examples htipsulmaew.wdechools.comicle.functions_parameters.pha UPGRADE NEWSLETTER REPORT ERROR Get Certified HTML Certificate css certificate JavaScript Certificate Front End Certificate SQL Certificate Python Certificate PHP Certificate Query Certificate Login W3.css c 718‘11212028 20.49 ¢ Function Parameters 3 WW tutoriatse Exercises» Servicesey Q @ schools SignUp Login = CSS JAVASCRIPT SQL. PYTHON = JAVA. PHP-—«S« HOWTO _—W3.CSS. G@ @& ® © Forum asour \W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 1999-2023 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSs. htipsulmaew.wdechools.comicle.functions_parameters.pha 8
You might also like
PPS Unit-04 Notes
PDF
No ratings yet
PPS Unit-04 Notes
27 pages
Introduction To Programming Unit 5
PDF
No ratings yet
Introduction To Programming Unit 5
23 pages
Unit 3 Functions and Program Structure-1-1
PDF
No ratings yet
Unit 3 Functions and Program Structure-1-1
26 pages
Fuction C Programming
PDF
No ratings yet
Fuction C Programming
46 pages
Module 3
PDF
No ratings yet
Module 3
118 pages
R Functions
PDF
No ratings yet
R Functions
35 pages
C Functions
PDF
No ratings yet
C Functions
36 pages
Notes On C Prog
PDF
No ratings yet
Notes On C Prog
28 pages
En Cours Functions
PDF
No ratings yet
En Cours Functions
24 pages
1.explain About Functios: Advantage of Functions in C o
PDF
No ratings yet
1.explain About Functios: Advantage of Functions in C o
14 pages
Class 3 Notes
PDF
No ratings yet
Class 3 Notes
14 pages
Lecture 2.3.2 User Defined Function
PDF
No ratings yet
Lecture 2.3.2 User Defined Function
21 pages
C Functions (Call by Value N Call by Reference)
PDF
No ratings yet
C Functions (Call by Value N Call by Reference)
20 pages
FUNCTIONS
PDF
No ratings yet
FUNCTIONS
29 pages
PPS - Unit 3
PDF
No ratings yet
PPS - Unit 3
135 pages
User Defined Function Recursion
PDF
No ratings yet
User Defined Function Recursion
35 pages
C Programming
PDF
No ratings yet
C Programming
100 pages
Httpssoul - Su.edu - Phpluginfile.php1522235mod Resourcecontent3Functions20and20Structured20Programming PDF
PDF
No ratings yet
Httpssoul - Su.edu - Phpluginfile.php1522235mod Resourcecontent3Functions20and20Structured20Programming PDF
14 pages
13 Function
PDF
No ratings yet
13 Function
7 pages
User Defined Functions
PDF
No ratings yet
User Defined Functions
22 pages
Chapter 6 User-Defined Functions
PDF
No ratings yet
Chapter 6 User-Defined Functions
44 pages
Unit 3 Topic 2
PDF
No ratings yet
Unit 3 Topic 2
19 pages
Lecture 08
PDF
No ratings yet
Lecture 08
46 pages
Unit 4
PDF
No ratings yet
Unit 4
62 pages
Pass Arrays To A Function in C
PDF
No ratings yet
Pass Arrays To A Function in C
4 pages
Unit 7 Function
PDF
No ratings yet
Unit 7 Function
12 pages
Unit 2 Functions
PDF
No ratings yet
Unit 2 Functions
71 pages
8.user Defined Function in C
PDF
No ratings yet
8.user Defined Function in C
23 pages
Functions and Recursion
PDF
No ratings yet
Functions and Recursion
19 pages
Lec 7 Functions
PDF
No ratings yet
Lec 7 Functions
19 pages
Functions
PDF
No ratings yet
Functions
46 pages
PSP PPT 2
PDF
No ratings yet
PSP PPT 2
30 pages
CP Unit-IV - RIT CSE
PDF
No ratings yet
CP Unit-IV - RIT CSE
39 pages
Union in C
PDF
No ratings yet
Union in C
31 pages
C Program 4
PDF
No ratings yet
C Program 4
32 pages
Functions, Arrays and Basic Algorithms
PDF
No ratings yet
Functions, Arrays and Basic Algorithms
26 pages
C Program-Module 3
PDF
No ratings yet
C Program-Module 3
14 pages
Lecture Week 9.1
PDF
No ratings yet
Lecture Week 9.1
41 pages
Passing Arrays As Function Arguments in C
PDF
No ratings yet
Passing Arrays As Function Arguments in C
6 pages
Whiteboard 25-May-2024
PDF
No ratings yet
Whiteboard 25-May-2024
25 pages
Function
PDF
No ratings yet
Function
21 pages
Unit No 1 User Defined Functions and Pointer
PDF
No ratings yet
Unit No 1 User Defined Functions and Pointer
8 pages
Chapter 13 Functions
PDF
No ratings yet
Chapter 13 Functions
12 pages
PPS - Unit Iii
PDF
No ratings yet
PPS - Unit Iii
24 pages
Unit V Function
PDF
No ratings yet
Unit V Function
11 pages
Unit 3-Applying The Concept of Functions
PDF
No ratings yet
Unit 3-Applying The Concept of Functions
30 pages
CPS Module4 Notes by Chidanand S Kusur Dept of CSE - 241218 - 171651
PDF
No ratings yet
CPS Module4 Notes by Chidanand S Kusur Dept of CSE - 241218 - 171651
16 pages
CSE 121, Structured Programming Language (Eve) Shornaa
PDF
No ratings yet
CSE 121, Structured Programming Language (Eve) Shornaa
12 pages
Week 11 12
PDF
No ratings yet
Week 11 12
53 pages
Unit Iii
PDF
No ratings yet
Unit Iii
12 pages
C Functions
PDF
No ratings yet
C Functions
22 pages
Functions
PDF
No ratings yet
Functions
8 pages
Module 3
PDF
No ratings yet
Module 3
64 pages
Functions in C (Examples and Practice)
PDF
No ratings yet
Functions in C (Examples and Practice)
6 pages
Drill 4
PDF
No ratings yet
Drill 4
8 pages
Function
PDF
No ratings yet
Function
4 pages
Module 3 Functions
PDF
No ratings yet
Module 3 Functions
22 pages
13 Functions
PDF
No ratings yet
13 Functions
16 pages
Cfunc
PDF
No ratings yet
Cfunc
29 pages
C 44
PDF
No ratings yet
C 44
9 pages
C 3
PDF
No ratings yet
C 3
6 pages
C 21
PDF
No ratings yet
C 21
9 pages
C 9
PDF
No ratings yet
C 9
13 pages
C 29
PDF
No ratings yet
C 29
11 pages
C 14
PDF
No ratings yet
C 14
9 pages
C 17
PDF
No ratings yet
C 17
9 pages
C 20
PDF
No ratings yet
C 20
5 pages
C 1
PDF
No ratings yet
C 1
8 pages
C 45
PDF
No ratings yet
C 45
8 pages
C 39
PDF
No ratings yet
C 39
8 pages
C 26
PDF
No ratings yet
C 26
8 pages
C 30
PDF
No ratings yet
C 30
8 pages
C 25
PDF
No ratings yet
C 25
8 pages
C 11
PDF
No ratings yet
C 11
7 pages
C 8
PDF
No ratings yet
C 8
7 pages
C 52
PDF
No ratings yet
C 52
7 pages
C 12
PDF
No ratings yet
C 12
6 pages
C 36
PDF
No ratings yet
C 36
6 pages
C 43
PDF
No ratings yet
C 43
6 pages
C 33
PDF
No ratings yet
C 33
6 pages
C 32
PDF
No ratings yet
C 32
6 pages
C 22
PDF
No ratings yet
C 22
6 pages
C 6
PDF
No ratings yet
C 6
5 pages
C 5
PDF
No ratings yet
C 5
5 pages
C 41
PDF
No ratings yet
C 41
5 pages
C 55
PDF
No ratings yet
C 55
5 pages
C 50
PDF
No ratings yet
C 50
5 pages
C 27
PDF
No ratings yet
C 27
5 pages
C 2
PDF
No ratings yet
C 2
5 pages