10 - ICS103 Programming in C Lecture 10: Functions II 1...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 ICS103 Programming in C Lecture 10: Functions II
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Outline Introducing Functions that return multiple results What is a Pointer variable? Functions returning multiple results Triple use for Asterisk (*) More Examples
Background image of page 2
3 Introducing Functions that return multiple results So far, we know how to pass inputs into a function and how to use the return statement to send back at most one result from a function. However, there are many situations where we would like a function to return more than one result. Some Example are: Function to convert time in seconds into hours, minutes and seconds Function to find the quotient and remainder of a division Function to return maximum, minimum and average from a set of values In this lecture, we discuss how a function can return more than one result, which is archieved through output parameters, which are pointer variables . Thus, to be able to write functions that return multiple results, we first need to learn about pointer variables.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
What is a Pointer variable? A pointer variable is a special variable, that stores the address of other normal variable. If a pointer variable stores the address of a char variable, we call it a character pointer and so on. A normal variable directly contains a specific value. A pointer variable on the other hand, contains an address of a variable that contains a specific value. Pointers like any other variables must be declared before they can be used. A pointer variable is declared by preceding its name with an asterisk. Example: int *p; How can we initialize p? First we must have an integer variable, then we int n = 84; p = &n; Suppose that the int variable n is stored in the memory cell # 1024, then the following figure figure shows the relationship between n and p. n
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 13

10 - ICS103 Programming in C Lecture 10: Functions II 1...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online