YouTube2Text

[CS61C FA20] Lecture 03.3 - C Intro: C v. Java and C Syntax — Transcript

by CS 61C Departmental · 2,562 words · 396 segments · language en · Watch on YouTube

Full transcript

  1. 0:00and welcome back since so many of you
  2. 0:03have come from
  3. 0:03a java experience in 61b or some from
  4. 0:07another community college or from
  5. 0:08another university
  6. 0:09let's actually show you that you
  7. 0:11probably already know most of what you
  8. 0:13need to know for c
  9. 0:13there's a couple of details we'll spend
  10. 0:14a lot of time talking about the
  11. 0:15differences but let's talk about some of
  12. 0:17the similarities as well and
  13. 0:18do a comparing and contrast kind of
  14. 0:20thing so here's a beautiful table
  15. 0:22uh java is an object-oriented language
  16. 0:25you know that c is mostly a function
  17. 0:26language you can do some object stuff
  18. 0:28but really that's what uh c
  19. 0:30plus plus was for so see the idea the
  20. 0:32core id
  21. 0:33is a function the job of the core idea
  22. 0:34is is uh is a class or an abstract idea
  23. 0:38abstract data type you can make apps
  24. 0:41data types in c
  25. 0:41but it's a lot harder to do we haven't
  26. 0:43it's not as clean and simple it's just
  27. 0:44screaming you here's an absolute data
  28. 0:46type boom there's a factory
  29. 0:47instance that's a new object abstract
  30. 0:49data type harder to do in c unless you
  31. 0:51really do something to
  32. 0:52really do it right the way you compile
  33. 0:54in so i guess i mentioned before java is
  34. 0:57compiled java c
  35. 0:58hello.java creates this independent and
  36. 1:00machine independent byte code
  37. 1:01the way you compile c is gcc hello.c
  38. 1:04that could create some machine
  39. 1:05independent code machine language code
  40. 1:07machine dependent code
  41. 1:08c is the machine dependent java java's
  42. 1:11output java c's output is machine
  43. 1:12independent code
  44. 1:13the way you run it is you just have to
  45. 1:14say java hello on the java side you say
  46. 1:17that out and it out loads it into memory
  47. 1:19and then runs the program that's the
  48. 1:20more details of what the loader does
  49. 1:22we'll talk about that
  50. 1:22but 8. out is where you run the program
  51. 1:24by the way there's a way to specify the
  52. 1:26name of the output file
  53. 1:27if your source code is hello.c
  54. 1:30dash o put the word put the name of the
  55. 1:33executable i don't like to see any 61c
  56. 1:35student ever using a dot out they should
  57. 1:37say
  58. 1:37gcc dash o hello hello.c
  59. 1:40if it's just a simple program like hello
  60. 1:42world or something fun very small
  61. 1:44the point is you shouldn't be having it
  62. 1:45out to name your executable then you'll
  63. 1:47have
  64. 1:47if you have ten active deals what do
  65. 1:48they all do i don't know let's run it
  66. 1:50all of a sudden
  67. 1:50the robot starts moving and this you
  68. 1:52know printer starts no name your
  69. 1:54executables you know the heck that these
  70. 1:55things do
  71. 1:56the picture on the right is the you know
  72. 1:58you get to job the reason i don't like
  73. 1:59java as a first language in apcsa
  74. 2:01i advocate for using a blocks language
  75. 2:03or something else
  76. 2:05python would be great for for apcsa in
  77. 2:07high school is
  78. 2:08you have to teach the kid on the first
  79. 2:09day all the elements of the picture in
  80. 2:11java it's a little crazy
  81. 2:12and c the amount of things you need to
  82. 2:13teach them is not much you know there's
  83. 2:15this library that you're including that
  84. 2:16has a standard library standard io
  85. 2:18libraries you can have printf and some
  86. 2:19other things
  87. 2:20main we'll talk about the details of the
  88. 2:22main program but main
  89. 2:24void just says i'm not going to use any
  90. 2:26arguments for now just main
  91. 2:27i print f you can't you don't use print
  92. 2:30print f
  93. 2:30uh quotes you have to specify a new line
  94. 2:33not a print line for java gives you a
  95. 2:35free new line
  96. 2:36you have to actually specify the new
  97. 2:37line yourself in c and
  98. 2:39you have to return a value main returns
  99. 2:41a number we'll talk about
  100. 2:43functions returning this particular
  101. 2:44value and declaring that but main
  102. 2:45returns an integer
  103. 2:46and so 0 means success just as a little
  104. 2:49fyi
  105. 2:50zero is always success in unix because
  106. 2:52there could be a lot of ways things fail
  107. 2:54but only one the way they succeed
  108. 2:55so they decided well zero is going to be
  109. 2:57the success number and any other number
  110. 2:59might be something didn't go wrong it's
  111. 3:00kind of fun to see that
  112. 3:02so that worked so the return zero was
  113. 3:04the right idea when it worked uh if you
  114. 3:05didn't work return some other number and
  115. 3:07that would be a special code that you
  116. 3:08and the person calling you might agree
  117. 3:09oh if
  118. 3:10it's if it's seven that means file is
  119. 3:12not found if it's 12 that means
  120. 3:13i couldn't find the printer or something
  121. 3:17storage this is what differs this is why
  122. 3:20i love to t61c in the third class not in
  123. 3:22the first or second class because
  124. 3:24you want to be able to have layers of
  125. 3:25abstraction one of the layers of
  126. 3:26abstraction you have in java is that it
  127. 3:28manages the memory for you
  128. 3:29you say new it just works it handles it
  129. 3:32by your garbage collection hopefully you
  130. 3:33learned that in 61b
  131. 3:35you have to do this all yourself so all
  132. 3:37the
  133. 3:38kind of all the safety belts all the
  134. 3:41padded rooms are gone you're doing all
  135. 3:42the memory management yourself
  136. 3:44you can get in trouble another
  137. 3:46difference
  138. 3:47you've got c in java in terms of
  139. 3:49comments so this is old school and cc
  140. 3:52uh but in something we'll share with you
  141. 3:54c99 within a couple of slides
  142. 3:56talks about that actually they allow you
  143. 3:57to have the same comments as java so for
  144. 3:59now
  145. 4:00java and c are the same in comments if
  146. 4:01using c99 or later
  147. 4:04you have to say final if it's if it's a
  148. 4:05constant in java and pound define or
  149. 4:07const for a variable that's not a
  150. 4:09pound-defined global variable
  151. 4:11in c do you have a preprocessor yes you
  152. 4:14do in c
  153. 4:15you do not in java so we talked about
  154. 4:16that a moment ago
  155. 4:18you have to have a definition the
  156. 4:19beginning of the block and c in old
  157. 4:21school and cc
  158. 4:22but in new schools c99 and built and
  159. 4:24beyond you don't do it you can declare a
  160. 4:26variable right before you use it just
  161. 4:28like you can in java
  162. 4:30naming conventions this is still not
  163. 4:32clear there there are lots of people who
  164. 4:34have different naming conventions in
  165. 4:35java and instill in c as well in fact
  166. 4:38a lot of people it's not as clear python
  167. 4:41typically universally has the
  168. 4:42word with underscores looks like c but
  169. 4:44there's still a difference of opinion on
  170. 4:46how c is done so sometimes you'll see
  171. 4:47even our own projects will have
  172. 4:49um camel case or other different
  173. 4:50conventions but typically people have
  174. 4:52mostly agreed that it's the same
  175. 4:54kind of underscores separate words in c
  176. 4:56but actually most of the time
  177. 4:58seed what they do what they do is
  178. 4:59they'll come up with a
  179. 5:01short hand so rather than saying um
  180. 5:05let's see i don't know uh ascii
  181. 5:08ascii to integer you wouldn't write
  182. 5:10ascii to integer you say a-t-a-t-o-i
  183. 5:14so my point is sometimes the c
  184. 5:17the kind of old-school c is to convert
  185. 5:21the word into a really tight word like
  186. 5:22mv like unix commands like real that's
  187. 5:24the old school back in the 70s and 80s
  188. 5:26that's how they were thinking
  189. 5:27mvcp like a couple of letters for things
  190. 5:30so a lot of times a lot of
  191. 5:31the the words they should be more
  192. 5:33verbose and we've realized it should be
  193. 5:35more
  194. 5:35verbose but they're shorter in c
  195. 5:39the way you access the library is you
  196. 5:40import the module in java and you access
  197. 5:42the library access library with the
  198. 5:44pound sign include
  199. 5:45with either the curly list the angle
  200. 5:47brackets or the quotes
  201. 5:50finally most of the operators you see
  202. 5:52are identical you know
  203. 5:53assignment arithmetic uh augmented
  204. 5:56assignments you know plus
  205. 5:57equals minus equals there's a lot more
  206. 5:59than you probably haven't seen before
  207. 6:01uh bitwise logic that means operating
  208. 6:02the actual bits of things not on
  209. 6:04kind of logical values but like boolean
  210. 6:06logic below is
  211. 6:08the actual boolean value true or false
  212. 6:09and doing things with that but bitwise
  213. 6:11says work on the actual bits themselves
  214. 6:12which is nice it kind of works in
  215. 6:14parallel very powerful
  216. 6:15you can move things around shift them
  217. 6:16around with a bit by shift
  218. 6:18testing for quality is the same you
  219. 6:20group them with parentheses
  220. 6:21the relationships orders you can
  221. 6:23increment a decrement with plus plus and
  222. 6:24minus minus
  223. 6:26member selection we'll talk about this
  224. 6:27some more this is how you kind of get
  225. 6:29into the fields say of a struct we'll
  226. 6:32talk about that a little later
  227. 6:33conditional evaluation which we call uh
  228. 6:34the inline if or ternary if
  229. 6:36uh is the same as well has there been an
  230. 6:39update to the ncc that i
  231. 6:41picture i showed you the beginning yes
  232. 6:42there has been it's called c99
  233. 6:45so if you hear me saying c99 or beyond
  234. 6:47in 1999
  235. 6:48a consortium got together and says we
  236. 6:50gotta upgrade c he said all right let's
  237. 6:51do this before remember
  238. 6:52ansi was in ncc spot about 86 1986.
  239. 6:56so they decided to do the by the way i
  240. 6:58think i still think that they should
  241. 6:59have used uh
  242. 7:00why why why why i mean 99 we keep
  243. 7:03working with this for another 100 years
  244. 7:05we're like do you give me 99 in 1999 or
  245. 7:072000
  246. 7:08it's a little crazy that they didn't
  247. 7:09think about the y2k problem and i
  248. 7:10already tried to have four digits for
  249. 7:11their but they didn't
  250. 7:12remember this is still the very abridged
  251. 7:15way of naming things so 99 is fine all
  252. 7:17right
  253. 7:17i guess i'll be fine let's see how we
  254. 7:19maybe they'd say oh c won't last 100
  255. 7:20years who knows
  256. 7:21um the way you can find out what version
  257. 7:23of c you're running is this little print
  258. 7:24left if you say printf
  259. 7:25percent ld long decimal and you have
  260. 7:27this constant standard c version it'll
  261. 7:29tell you what number that is and that
  262. 7:30that is the number which is 1999.01 it's
  263. 7:33just a big number
  264. 7:34but that's the actual date of that the
  265. 7:36release of that version you see
  266. 7:38you're working with actually the
  267. 7:39compiler you're working with really
  268. 7:41references there's a wikipedia link to
  269. 7:42that here's some things that you'll see
  270. 7:44that are different from ncc so if you
  271. 7:46see old school c you're probably not
  272. 7:47going to see a lot of old school c
  273. 7:48probably the code did it but maybe you
  274. 7:49get a job that you see
  275. 7:50old ncc you need to know that's ncc and
  276. 7:53maybe
  277. 7:54hopefully you'll have a c99 or above
  278. 7:56compiler that you're working with
  279. 7:58but if you see old school c that's doing
  280. 7:59something weird you'll see that's
  281. 8:01because of these reasons that you had to
  282. 8:02have declarations at the top
  283. 8:04now you can have declarations anywhere
  284. 8:05thanks to c89 declarations can be
  285. 8:07anywhere java like comments we talked
  286. 8:08about
  287. 8:09this is a big deal boy all the code i
  288. 8:11wrote from 86 to 99 was so bad because
  289. 8:14you couldn't have a variable length
  290. 8:16array you had to have that be a constant
  291. 8:18and there's nothing you could say
  292. 8:19hey user how big a radio you want oh 100
  293. 8:21okay make an array
  294. 8:22we'll talk about what a raise are later
  295. 8:24then of a hundred you couldn't do that
  296. 8:25you had to hard code the number into the
  297. 8:27code itself you couldn't ask dynamically
  298. 8:29what the size something is in an array
  299. 8:30that was a big deal so that third bullet
  300. 8:32down i'm like
  301. 8:33very happy another thing you're going to
  302. 8:35see in a couple slides
  303. 8:36is how big are things how big is an
  304. 8:39integer
  305. 8:40well it used to depend uh and in type
  306. 8:43said
  307. 8:43enough with this depending it should
  308. 8:45just be clear you should be able to
  309. 8:46specify how wide integers are i think
  310. 8:48you've said that you've seen that before
  311. 8:49in the number representation you can say
  312. 8:50i want it to be 8 or 16 or 32 or 64.
  313. 8:53um so they have that so please use n
  314. 8:55types rather than in
  315. 8:56i recommend and standard bull lets you
  316. 8:58actually have booleans we never had
  317. 8:59booleans at all we always had zeros and
  318. 9:01ones
  319. 9:01and we now actually have booleans that
  320. 9:02you can use if you use the standard
  321. 9:04boolean
  322. 9:04library has there been an upgrade to 79
  323. 9:07yes there has been it's called c11 and
  324. 9:09now actually the newest one is called
  325. 9:10c18 which actually is mostly c11 which
  326. 9:12has bug fixes
  327. 9:13and here's the two numbers you get 20
  328. 9:162011 and 2017 for the longs
  329. 9:18there's references here now is just one
  330. 9:20reference for all c standard revisions
  331. 9:22you now have multi-threading
  332. 9:24multi-threading support which is amazing
  333. 9:26you now have unicode you really we
  334. 9:27talked about unicode the last series of
  335. 9:29lectures we can now support unicode in c
  336. 9:31that was a big deal
  337. 9:32get-ass was a huge security hole for so
  338. 9:34many years they got that out of there
  339. 9:36and some more some more things that are
  340. 9:37not so complex values if you care about
  341. 9:39that
  342. 9:40some type generic macros some other
  343. 9:41things like that pretty cool stuff so
  344. 9:42there's a lot of things
  345. 9:43check out the wikipedia if you want to
  346. 9:45use those you probably won't use most of
  347. 9:46those in this class but it's pretty
  348. 9:47exciting
  349. 9:48as i mentioned before you've got this
  350. 9:50main before we had a vote in there
  351. 9:51saying you know what i don't need any
  352. 9:52arguments i'll just say void
  353. 9:54if you want to be able to process
  354. 9:55arguments you have to say the following
  355. 9:56into arg c
  356. 9:57care star argv open close square
  357. 10:01brackets what that means is
  358. 10:02rxc says how many arguments do you have
  359. 10:05however
  360. 10:06it starts arguing by the way and the
  361. 10:08index of that starts we
  362. 10:09you know i haven't told you this but c
  363. 10:10is zero indexed so the first guy in that
  364. 10:12array is index is zero just like python
  365. 10:15and unlike scratch and snap is which is
  366. 10:17one index the next one is a one the next
  367. 10:19is a two
  368. 10:20so here arg c is two why is argc
  369. 10:23two because there's two things there
  370. 10:25sort and my
  371. 10:27file interesting so arc v arc v
  372. 10:30of zero is sort it's the name of the
  373. 10:33executable it's the name of the program
  374. 10:34itself
  375. 10:36arc v of 1 is my file so that's kind of
  376. 10:38cool right so you can still go from 0
  377. 10:40up to but let up to less than in some
  378. 10:42loop and you'll process through all the
  379. 10:44things that were passed into you
  380. 10:45you don't you can't ever get to the arg
  381. 10:47v of two because if
  382. 10:48it's an array it has two guys it's zero
  383. 10:50one uh
  384. 10:52zero and one you only have two guys zero
  385. 10:54and one you can't get to arg v of two
  386. 10:55if you actually uh if you had handed arc
  387. 10:57c of two
  388. 11:00so why do you might think to yourself
  389. 11:03why would you ever care about getting
  390. 11:04the name of the program
  391. 11:06think about that i'm gonna leave that
  392. 11:08out there and see if you can figure out
  393. 11:09why you might actually want the name of
  394. 11:10the program
  395. 11:11in the program itself think about that
  396. 11:16we'll see the next video

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 03.3 - C Intro: C v. Java and C Syntax by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 2,562 words across 396 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.