Point Eurs
Point Eurs
Point Eurs
Lecture 3
Today’s Schedule
▪ Pointers
▪ Argument Passing Conventions
▪ Arrays
▪ Pointers
▪ Argument Passing Conventions
▪ Arrays
int a = 3;
int b = 8;
printf("%d, %d\n", a, b);
swap(a, b);
printf("%d, %d\n", a, b);
Output:
3, 8
8, 3
▪ Pointers
▪ Argument Passing Conventions
▪ Arrays
▪ If the function does not return a value, the return type should be
void
▪ If there are no arguments, then the argument list is void (not
required)
▪ Let’s dig a bit deeper into this…
Here’s an example:
▪ Reason 2: Speed!
▪ Return values have to be copied back to the calling
function
▪ Say my function returns a bitmap image. The entire
thing is going to get copied!
▪ In a language that focuses on speed and efficiency,
updating the values directly in memory is faster
▪ Imagine transferring lots of large strings, objects, etc.
around your program, copying them the whole time
And:
/* Takes no args: */
void function(void);
▪ Pointers
▪ Argument Passing Conventions
▪ Arrays
// Will auto-size to 5:
int nums[] = { 1, 82, 9, -3, 26 };
int list[] = {
1,
2,
15,
2001
};
sizeof(int) = 4
target: dependency
instructions
▪ You provide a target, like ‘array’ – the name of the file that gcc
will generate
▪ The dependency tells us what files you need to build your
program. In this case, it’s ‘array.c’