From the course: C Standard Library
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Memory allocation example - C Tutorial
From the course: C Standard Library
Memory allocation example
- [Instructor] In this example I want to illustrate the importance of allocating memory. So if you take a look at this code in line four we have a definition for a character pointer, that's a string, str. And the main function is very simple. First it goes scanf to read all the characters that come in from the keyword until it finds a new line corrector. That's when someone presses Enter. And lastly, printf just prints that string. This looks very simple doesn't it? Well let's see it working. So let me type in this is so easy. Whoa, notice how the program finished early. I know this because the string wasn't printed out. And look at the return value, this isn't normal. The return value says 3221225477. So what's that big number? Well that's the operating system complaining that scanf was trying to write into some place in the memory it doesn't have any permission to write into. And why would that happen? Well we'll have to look at the code again. So if you take a look at line four…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Memory allocation1m 32s
-
(Locked)
Memory allocation example2m 29s
-
(Locked)
Random number generation1m 48s
-
(Locked)
Random number generation example2m 40s
-
(Locked)
String conversion2m 11s
-
(Locked)
String conversion example6m 29s
-
(Locked)
Sort and search1m 52s
-
(Locked)
Sort and search main4m 50s
-
(Locked)
Sort and search functions5m 6s
-
(Locked)
Challenge: Let's get random1m 38s
-
(Locked)
Solution: Let's get random5m 40s
-
-
-
-