blob: 37e1bfd7f9992a3c7bcf16f00933759144d128f4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
/************************************************************************
*
* Purpose: Program to demonstrate passing a pointer to a scalar to
* a function.
* Author: M J Leslie.
* Date: 11-Apr-94
*
************************************************************************/
void add(int*); /* Function declaration */
main()
{
int i=4; /* variable declaration */
int* ptr; /* int pointer */
ptr = &i; /* 'ptr' now contains the
address of 'i' */
printf("i starts out life as %d.\n", i);
printf(" *ptr is %d.\n", *ptr);
add(ptr); /* Function call */
printf(" i is now %d.\n", i);
}
/************************************************************************/
void add(int *ptr) /* Function definition */
{
++*ptr; /* Add 1 to the value
* pointed too by 'ptr' */
return;
}
|