YouTube2Text

[CS61C FA20] Lecture 04.4 - C Intro: Pointers, Arrays, Strings: Function Pointer Example — Transcript

by CS 61C Departmental · 430 words · 67 segments · language en · Watch on YouTube

Full transcript

  1. 0:00and welcome back now let's look at a
  2. 0:02function pointer example to actually see
  3. 0:05how we would do that with c this is the
  4. 0:08only slide we're going to show
  5. 0:10for this lecture so let's actually jump
  6. 0:12in
  7. 0:13let's go here and grab the pen and
  8. 0:17what does this do so we define two very
  9. 0:20simple functions
  10. 0:22x10 which is times 10 and times two if
  11. 0:24you look at this all they do is return
  12. 0:26double the input or 10 times the input
  13. 0:28very easy okay
  14. 0:30i declare print array is just a simple
  15. 0:32thing that's just going to print the
  16. 0:33array nothing special here
  17. 0:34and here is mutate map okay what i want
  18. 0:37to write is map
  19. 0:38the simple higher function of map takes
  20. 0:40a function and a list and it's going to
  21. 0:42return a new list with that function
  22. 0:44applied to every element of it but
  23. 0:46actually mutate map is easier because i
  24. 0:47haven't really told you how to
  25. 0:48make new space of things dynamically so
  26. 0:50that'll be later so we're going to have
  27. 0:52to actually change
  28. 0:53the input okay but same idea so
  29. 0:57here is mutated map it takes the array
  30. 0:59it takes the size i mentioned before in
  31. 1:01earlier lecture you have to pass in the
  32. 1:02array and the size to it
  33. 1:03and here look at this this is the way
  34. 1:06you declare to say
  35. 1:07i'm going to receive a fp is going to be
  36. 1:10a function pointer
  37. 1:12that's going to return an int take an
  38. 1:14int take an int
  39. 1:16and return an it that's that's the you
  40. 1:18know these that's the
  41. 1:19x2 or x10 okay that's it nothing else is
  42. 1:22magical
  43. 1:23so here's the code here's the main i
  44. 1:25make an array first three digits of pi
  45. 1:27three one four and it's three
  46. 1:29of the three three numbers in here i
  47. 1:31print the array
  48. 1:32there's my three one four i call mutate
  49. 1:35map watch this address of x10
  50. 1:39i pass in a pointer to x text 10.
  51. 1:42x2 times 2 i pass in the double that's
  52. 1:45the double function
  53. 1:47what does it do it mutates a
  54. 1:50and now it prints it out print array
  55. 1:52prints it out 628
  56. 1:54that's pretty cool i pass in the 10
  57. 1:57times function
  58. 1:58and i print the array and there's 60 20
  59. 2:0080. this simple piece of code is how you
  60. 2:03would use
  61. 2:03a function pointer yourself now you can
  62. 2:05think of writing really general
  63. 2:06procedures that don't just use
  64. 2:08that consume data but actually consume
  65. 2:10other functions too and are more general
  66. 2:11pretty cool
  67. 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.