Class Notes (1,049,967)
CA (601,050)
Seneca (1,318)
(37)
Lecture

Computer Programming and Analysis IPC144 Lecture Notes - Function Prototype

4 pages158 viewsWinter 2014

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

This preview shows page 1. 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;
}
You're Reading a Preview

Unlock to view full version


Loved by over 2.2 million students

Over 90% improved by at least one letter grade.