Class Notes (975,742)
CA (575,152)
Seneca (1,145)
Lecture

Computer Programming and Analysis IPC144 Lecture Notes - Function Prototype

4 Pages
422 Views
Winter 2014

Department
Computer Programming and Analysis
Course Code
Computer Programming and Analysis IPC144
Professor
Arta Kogan

This preview shows page 1. Sign up to view the full 4 pages of the document.
IPC144 Week 5 Part 2
Agenda:
1 More pointers
2 Homework
More Pointers
Pointers can be used to access and modify the local variables from another function. In
order to do that the address of the variable is passed to the function. Then the value of the
variable is changed inside of the function using its address. The main advantage of using
pointers is that a function can return (change) more then one value.
Example 1: fun15.c
void func(int *p);
/* an example of a function prototype – function will receive an address and store it into a
pointer p */
int func2(int *p, double *p_num, int another_num);
/* an example of the function prototype – function will receive three parameters:
an address of an integer – and use the pointer p to store it
an address of a double – and use pointer p_num to store it
a value of an integer – and an integer another_num to store it
*/
int main(){
int num, x, z = 54;
double y = 5.6;
func(&x);
/* an example of a function call – sending an address to the function */
num = func2(&x, &y, z);
/* Important!! Three parameters are sent:
the address of an integer x
the address of a double y
and a copy of the value of an integer z */
printf(“x = %d, y = %.2lf, z = %d, num is %d\n”, x, y, z, num);
return 0;
}

Loved by over 2.2 million students

Over 90% improved by at least one letter grade.

Leah — University of Toronto

OneClass has been such a huge help in my studies at UofT especially since I am a transfer student. OneClass is the study buddy I never had before and definitely gives me the extra push to get from a B to an A!

Leah — University of Toronto
Saarim — University of Michigan

Balancing social life With academics can be difficult, that is why I'm so glad that OneClass is out there where I can find the top notes for all of my classes. Now I can be the all-star student I want to be.

Saarim — University of Michigan
Jenna — University of Wisconsin

As a college student living on a college budget, I love how easy it is to earn gift cards just by submitting my notes.

Jenna — University of Wisconsin
Anne — University of California

OneClass has allowed me to catch up with my most difficult course! #lifesaver

Anne — University of California
Description
IPC144 Week 5 Part 2 Agenda: 1 More pointers 2 Homework More Pointers Pointers can be used to access and modify the local variables from another function. In order to do that the address of the variable is passed to the function. Then the value of the variable is changed inside of the function using its address. The main advantage of using pointers is that a function can return (change) more then one value. Example 1: fun15.c void func(int *p); /* an example of a function prototype – function will receive an address and store it into a pointer p */ int func2(int *p, double *p_num, int another_num); /* an example of the function prototype – function will receive three parameters: an address of an integer – and use the pointer p to store it an address of a double – and use pointer p_num to store it a value of an integer – and an integer another_num to store it */ int main(){ int num, x, z = 54; double y = 5.6; func(&x); /* an example of a function call – sending an address to the function */ num = func2(&x, &y, z); /* Important!! Three parameters are sent: the address of an integer x the address of a double y and a copy of the value of an integer z */ printf(“x = %d, y = %.2lf, z = %d, num is %d\n”, x, y, z, num); return 0; } /* function definitions */ void func(int *p){ *p = 77; } int func2(int *p, double *p_num, int another_num){ *p = another_num; another_num ++; *p_num = 56.34; another_num += *p; return another_num – 5; } Example 2: /* walk12.c */ /* determine the exact output of the following program */ void go_on(int *p, int x); int main(){ int a = 7; int *pointer; pointer = &a;
More Less
Unlock Document

Only page 1 are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

You've reached the limit of 4 previews this month

Create an account for unlimited previews.

Already have an account?

Log In


OR

Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit