overview (1a)€¦ · version 1.2 or any later version published by the free software foundation;...
TRANSCRIPT
![Page 1: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/1.jpg)
Young Won Lim9/20/17
Overview (1A)
![Page 2: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/2.jpg)
Young Won Lim9/20/17
Copyright (c) 2009 - 2017 Young W. Lim.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".
Please send corrections (or suggestions) to [email protected].
This document was produced by using OpenOffice.
![Page 3: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/3.jpg)
Overview 3 Young Won Lim9/20/17
Calculating the Mean
The mean of 3 numbers m =a b c
3
40 + 50 + 603
=1503
= 50
45 53 633
=1613
= 53.6666666 ...
Integer number
Real number
fixed point number
floating point number
![Page 4: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/4.jpg)
Overview 4 Young Won Lim9/20/17
Calculating a mean in C
* Variable* Type* Assignment* Operator
int a, b, c;int mean;
a = 40;b = 50;c = 60;
mean = (a + b +c) / 3;
int a, b, c;float mean;
a = 45;b = 53;c = 63;
mean = (a + b +c) / 3.0;
![Page 5: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/5.jpg)
Overview 5 Young Won Lim9/20/17
Variables – int Type
a
b
c
mean
a
b
c
mean
40
50
60
50
int a, b, c;int mean;
a = 40;b = 50;c = 60;mean = (a + b +c) / 3;
![Page 6: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/6.jpg)
Overview 6 Young Won Lim9/20/17
Variables – float Type
a
b
c
mean
a
b
c
mean
int a, b, c;float mean;
a = 45;b = 53;c = 63;
mean = (a + b +c) / 3.0;
45
53
63
53.6...67
float type
![Page 7: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/7.jpg)
Overview 7 Young Won Lim9/20/17
C and assembly code view of variables
a
b
c
mean
40
50
60
50
address data
4500
4510
4520
4530
40
50
60
50
variablename
variablevalue
c source code view
assembly code viewCompiler
![Page 8: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/8.jpg)
Overview 8 Young Won Lim9/20/17
Memory : (Address, Data)
a value
b value
c value
mean value
address data
4500
4510
4520
4530
40
50
60
50
compiler determines the addresses
a address
b address
c address
mean address
![Page 9: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/9.jpg)
Overview 9 Young Won Lim9/20/17
Getting the addresses of variables
&variable address
address of a
address of b
address of c
address of mean
&a
&b
&c
&mean
Addresses determined by a compiler
![Page 10: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/10.jpg)
Overview 10 Young Won Lim9/20/17
Example: a variable stored in memory
&variable address
4500
40
4500 40&a a
&a
a
:address (where)
:data (what)
int a;
a = 40;
![Page 11: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/11.jpg)
Overview 11 Young Won Lim9/20/17
Variables and the & operator
a
b
c
mean
40
50
60
50
address data
&a: 4500
&b: 4510
&c: 4520
&mean: 4530
a: 40
b: 50
c: 60
mean: 50
int a=40, b=50, c=60;int mean=(a+b+c)/3;
![Page 12: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/12.jpg)
Overview 12 Young Won Lim9/20/17
Graphical representation of address assignment
&a: 4500 a = 40
&p p= &a pointer variable
a = 40;
p = &a;
Value assignment to a
Address assignment to p
int a ;
int * p ;
4500
integer variable
an arrow a pointer
![Page 13: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/13.jpg)
Overview 13 Young Won Lim9/20/17
Data and Address Operators
&variable address
address of a
address of b
address of c
address of mean
&a
&b
&c
&mean
*address data
data at the address of a
data at the address of b
data at the address of c
data at the address of mean
*(&a)
*(&b)
*(&c)
*(&mean)
Address operator Data operator
![Page 14: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/14.jpg)
Overview 14 Young Won Lim9/20/17
The & and * operators
the value at an address :Dereferencing operator *
a
The address of a variable :Address of operator &
&
& a
*
*p p
![Page 15: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/15.jpg)
Overview 15 Young Won Lim9/20/17
&a and *p
int a ; int * p ;
integer variable a pointer variable p
&a *p
a must be a variable
p’s value must be an address
![Page 16: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/16.jpg)
Overview 16 Young Won Lim9/20/17
The address &a and the variable *p
int a ; int * p ;
integer variable a pointer variable p
a a variable p an address
&a an address *p a variable
![Page 17: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/17.jpg)
Overview 17 Young Won Lim9/20/17
R/W Accessing &a and *p
int a ; int * p ;
integer variable a pointer variable p
* p = … (write)
... = * p (read)
& a = … (write)
... = & a (read)
like a constant like a variable
![Page 18: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/18.jpg)
Overview 18 Young Won Lim9/20/17
&a and *p examples
a
&
& a
*
*p p
int a ; int * p ;
p &p
&
integer variable a pointer variable p
The value of p is an address.The data at that address is *p
![Page 19: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/19.jpg)
Overview 19 Young Won Lim9/20/17
The & and * operators [int a]
a
&
& a
*
a & a
int a ;
integer variable a
int a ;
integer variable a
*(& a) = a
![Page 20: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/20.jpg)
Overview 20 Young Won Lim9/20/17
The & and * operators [int *p]
p & p p & p
&
*
*(&p) = p
value of p (→ an address)
&(p) = &p
value of p (→ an address)
int * p ;
pointer variable p
int * p ;
pointer variable p
*p p *p p
&&(*p) = p
*
*(p) = *p
![Page 21: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/21.jpg)
Overview 21 Young Won Lim9/20/17
The & and * operators [int *p]
p & p p & p
&
*
*p p *p p
&
*
![Page 22: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/22.jpg)
Overview 22 Young Won Lim9/20/17
The & and * operators [int *p]
&(*p) = p
*(&p) = p
the value at an address :Dereferencing operator *
The address of a variable :Address of operator &
&(p) = &p
*(p) = *p
int * p ;
pointer variable p
int * p ;
pointer variable p
![Page 23: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/23.jpg)
Overview 23 Young Won Lim9/20/17
The & and * cancel each other
p
*p p
& p p
*p p
& p
&
&(*p) = p
*
*(& p) = p
&
*
&(*p) = p
*(& p) = p
[1]
[2]
[1]
[2]
![Page 24: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/24.jpg)
Overview 24 Young Won Lim9/20/17
Pointer Type Declaration
&a
&p
value of p(→ an address)
a
p
*p
int a;
int *p;
p holds address *p holds integer value
a holds integer value
p
![Page 25: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/25.jpg)
Overview 25 Young Won Lim9/20/17
where: the address of p
what: the value of p &a (address of a)
Address assignment to a pointer variable
p = &a;
int *p;
The value of p is the address &a
“p points to &a”“p points to where the variable a is stored “
Address assignment
![Page 26: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/26.jpg)
Overview 26 Young Won Lim9/20/17
Address assignment example
p = &a;
int *p; address data
&a: 4500
&b: 4510
&c: 4520
&mean: 4530
a: 40
b: 50
c: 60
mean: 50
&p: 4540 p: 4500
Address assignment
![Page 27: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/27.jpg)
Overview 27 Young Won Lim9/20/17
where: the location where the value of p points to (value of p → address)
what: the data at p 55 (an integer value)
Value assignment to a pointer variable
p = &a;
int *p;
*p = 55; Value assignment
![Page 28: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/28.jpg)
Overview 28 Young Won Lim9/20/17
Value assignment to a pointer variable
p = &a;
int *p;address data
&a: 4500
&b: 4510
&c: 4520
&mean: 4530
*p: a: 55
b: 50
c: 60
mean: 50
&p: 4540 p: 4500
*p = 55;
p:
Value assignment
![Page 29: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/29.jpg)
Overview 29 Young Won Lim9/20/17
Function examples – passing values
int vsum (int a, int b) {
return (a + b);}
S = vsum ( x, y);
int x=3, y=5;
...
...
function call
function definition
![Page 30: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/30.jpg)
Overview 30 Young Won Lim9/20/17
Function examples – passing addresses
int asum (int *a, int *b) {
return (*a + *b);}
S = asum ( &x, &y);
int x=3, y=5;
...
...
function call
function definition
![Page 31: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/31.jpg)
Overview 31 Young Won Lim9/20/17
Comparison
int vsum (int a, int b) {
return (a + b);}
int asum (int *a, int *b) {
return (*a + *b);}
S = vsum ( x, y); S = asum ( &x, &y);
a = x; b = y;
a + b = x + y
a = &x; b = &y*a = *(&x); *b = *(&y)
*a + *b = x + y
int x, y; int x, y;...
...
![Page 32: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/32.jpg)
Overview 32 Young Won Lim9/20/17
Differences
int vsum (int a, int b) { int val = a + b; a = b = 0;
return (val); }
int asum (int *a, int *b) {
int val = *a + *b;
*a = *b = 0;
return (val);
}
S = vsum ( x, y); S = asum ( &x, &y);
int x, y; int x, y;
x, y : no change x, y : changed to zeros
*(&x) = *(&y) = x = y = 0
![Page 33: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/33.jpg)
Overview 33 Young Won Lim9/20/17
printf() : the built-in function
Expected Output
The mean of three numbersa = 40b = 50c = 60mean(40, 50, 60) => 50
printf(“The mean of three numbers \n”);printf(“a = %d \n”, a);printf(“b = %d \n”, b);printf(“c = %d \n”, c);printf(“mean (%d, %d, %d) => %d \n”, a, b, c, mean);
![Page 34: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/34.jpg)
Overview 34 Young Won Lim9/20/17
scanf() : another built-in function
Input Example
Enter three numbers!a = 40
b = 50
c = 60
printf(“Enter three numbers! \n”);printf(“a = ”); scanf(“ %d”, &a);printf(“b = ”); scanf(“ %d”, &b);printf(“c = ”); scanf(“ %d”, &c);
address value
40
50
60
&a: 4500
&b: 4510
&c: 4520
![Page 35: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/35.jpg)
Overview 35 Young Won Lim9/20/17
The Main Function (1)
main (void) {
int a, b, c;int mean;
a = 40;b = 50;c = 60;
mean = (a + b + c) / 3;
printf(“The mean of three numbers \n”);printf(“a = %d \n”, a);printf(“b = %d \n”, b);printf(“c = %d \n”, c);printf(“mean (%d, %d, %d) => %d \n”, a, b, c, mean);
}
![Page 36: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/36.jpg)
Overview 36 Young Won Lim9/20/17
The Main Function (2)
main (void) {
int a, b, c;int mean;
printf(“Enter three numbers! \n”);printf(“a = ”); scanf(“ %d”, &a);printf(“b = ”); scanf(“ %d”, &b);printf(“c = ”); scanf(“ %d”, &c);
mean = (a + b + c) / 3;
printf(“The mean of three numbers \n”);printf(“a = %d \n b = %d \n c = %d \n”, a, b, c);printf(“mean (%d, %d, %d) => %d \n”,
a, b, c, mean );
}
![Page 37: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/37.jpg)
Overview 37 Young Won Lim9/20/17
The Main Function (3)
main (void) {
int a, b, c;int mean;
get_numbers( ? );
compute_mean( ? );
print_numbers( ? );
}
![Page 38: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/38.jpg)
Overview 38 Young Won Lim9/20/17
Function compute_mean()
* Call by Value
int compute_mean (int x, int y, int z) ;
main (void) {
int mean;
mean = compute_mean(40, 50, 60);
}
int compute_mean (int x, int y, int z) {
int avg;
avg = (x + y + z) / 3;
return( avg );
}
* Local Variable
int values are copied
* Return Value
![Page 39: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/39.jpg)
Overview 39 Young Won Lim9/20/17
Function get_numbers()
void get_numbers (int *x, int *y, int *z) ;
main (void) {
int a, b, c;
get_numbers(&a, &b, &c);
}
void get_numbers (int * x, int * y, int * z) {
printf(“Enter three numbers! \n”);printf(“a = ”); scanf(“ %d”, x);printf(“b = ”); scanf(“ %d”, y);printf(“c = ”); scanf(“ %d”, z);
}
* Call by Reference
addresses are copied
* No Return Value
![Page 40: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/40.jpg)
Overview 40 Young Won Lim9/20/17
Call by Value & Call by Reference
mean = compute_mean(40, 50, 60);
int compute_mean (int x, int y, int z)
get_numbers(&a, &b, &c);
void get_numbers (int * x, int * y, int * z)
&x
40 50 60
x=40 y=50 z=60&y &z
40 50 60&a &b &c
&x x=&a y=&b z=&c&y &z
* Call by Reference
* Call by Value
![Page 41: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/41.jpg)
Overview 41 Young Won Lim9/20/17
Change the caller’s variables
* Call by Reference
40 50 60&a &b &c
address value
&x x=&a y=&b z=&c&y &z
Now, values of a, b, c are changed in the get_numbers() function
*x= 100;*y= 200;*z= 300;
a= 100;b= 200;c= 300;
100 200 300&a &b &c
Caller’s Variables
The callee can change the values of the caller’s variables
![Page 42: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/42.jpg)
Overview 42 Young Won Lim9/20/17
Function print_numbers()
void print_numbers (int x, int y, int z, int avg) {
printf(“The mean of three numbers \n”);printf(“a = %d \n b = %d \n c = %d \n”, x, y, z);printf(“mean (%d, %d, %d) => %d \n”, x, y, z, avg);
}
main (void) {
int a, b, c;int mean;
print_numbers(a, b, c, mean);
}
* Call by Value
* No Return Value
![Page 43: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/43.jpg)
Overview 43 Young Won Lim9/20/17
The Main Function (4)
void get_numbers (int *x, int *y, int *z);int compute_mean (int x, int y, int z);void print_numbers (int x, int y, int z, int avg);
main (void) {
int a, b, c;int mean;
get_numbers(&a, &b, &c);
mean = compute_mean(a, b, c);
print_numbers(a, b, c, mean);}
Prototypes
![Page 44: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/44.jpg)
Overview 44 Young Won Lim9/20/17
The Main Parameters (1)
#include <stdio.h>
int main(int argc, char *argv[])
{
int i;
printf("argc= %d \n", argc);
for (i=0; i<argc; ++i) {
printf("argv[%d] = %s \n", i, argv[i]);
}
}
![Page 45: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/45.jpg)
Overview 45 Young Won Lim9/20/17
The Main Parameters (2)
young@usys ~ $ ./a.outargc= 1 argv[0] = ./a.out
young@usys ~ $ ./a.out one two threeargc= 4 argv[0] = ./a.out argv[1] = one argv[2] = two argv[3] = three
young@usys ~ $ ./a.out one two three fourargc= 5 argv[0] = ./a.out argv[1] = one argv[2] = two argv[3] = three argv[4] = four
![Page 46: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/46.jpg)
Overview 46 Young Won Lim9/20/17
The Main Parameters (3)
young@usys ~ $ ./a.out one two argc= 3 argv[0] = ./a.out argv[1] = one argv[2] = two
argv[0] argv[1] argv[2]
a
.
o
u
t
\0
o
n
e
\0
t
w
o
\0
/
.
![Page 47: Overview (1A)€¦ · Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy](https://reader033.vdocument.in/reader033/viewer/2022060220/5f06f1077e708231d41a8043/html5/thumbnails/47.jpg)
Young Won Lim9/20/17
References
[1] Essential C, Nick Parlante[2] Efficient C Programming, Mark A. Weiss[3] C A Reference Manual, Samuel P. Harbison & Guy L. Steele Jr.[4] C Language Express, I. K. Chun