[CS61C FA20] Lecture 04.4 - C Intro: Pointers, Arrays, Strings: Function Pointer Example — Transcript
Full transcript
- 0:00and welcome back now let's look at a
- 0:02function pointer example to actually see
- 0:05how we would do that with c this is the
- 0:08only slide we're going to show
- 0:10for this lecture so let's actually jump
- 0:12in
- 0:13let's go here and grab the pen and
- 0:17what does this do so we define two very
- 0:20simple functions
- 0:22x10 which is times 10 and times two if
- 0:24you look at this all they do is return
- 0:26double the input or 10 times the input
- 0:28very easy okay
- 0:30i declare print array is just a simple
- 0:32thing that's just going to print the
- 0:33array nothing special here
- 0:34and here is mutate map okay what i want
- 0:37to write is map
- 0:38the simple higher function of map takes
- 0:40a function and a list and it's going to
- 0:42return a new list with that function
- 0:44applied to every element of it but
- 0:46actually mutate map is easier because i
- 0:47haven't really told you how to
- 0:48make new space of things dynamically so
- 0:50that'll be later so we're going to have
- 0:52to actually change
- 0:53the input okay but same idea so
- 0:57here is mutated map it takes the array
- 0:59it takes the size i mentioned before in
- 1:01earlier lecture you have to pass in the
- 1:02array and the size to it
- 1:03and here look at this this is the way
- 1:06you declare to say
- 1:07i'm going to receive a fp is going to be
- 1:10a function pointer
- 1:12that's going to return an int take an
- 1:14int take an int
- 1:16and return an it that's that's the you
- 1:18know these that's the
- 1:19x2 or x10 okay that's it nothing else is
- 1:22magical
- 1:23so here's the code here's the main i
- 1:25make an array first three digits of pi
- 1:27three one four and it's three
- 1:29of the three three numbers in here i
- 1:31print the array
- 1:32there's my three one four i call mutate
- 1:35map watch this address of x10
- 1:39i pass in a pointer to x text 10.
- 1:42x2 times 2 i pass in the double that's
- 1:45the double function
- 1:47what does it do it mutates a
- 1:50and now it prints it out print array
- 1:52prints it out 628
- 1:54that's pretty cool i pass in the 10
- 1:57times function
- 1:58and i print the array and there's 60 20
- 2:0080. this simple piece of code is how you
- 2:03would use
- 2:03a function pointer yourself now you can
- 2:05think of writing really general
- 2:06procedures that don't just use
- 2:08that consume data but actually consume
- 2:10other functions too and are more general
- 2:11pretty cool
- 2:12we'll see the next video
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 04.4 - C Intro: Pointers, Arrays, Strings: Function Pointer Example by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 430 words across 67 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.