Join Eduardo Corpeño for an in-depth discussion in this video Memory allocation example, part of C Standard Library.
- [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, the string, str,…which is a pointer to a character isn't pointing anywhere.…
- Working with header files
- C constants and types
- Unformatted and formatted input/output
- Accessing files with C functions
- Generating random numbers
- Converting strings
- Sorting and searching for data
- Manipulating strings
- Using mathematical functions
Skill Level Intermediate
C++ Standard Template Librarywith Eduardo Corpeño2h 23m Advanced
1. The C Standard Library
2. Input and Output Library: stdio.h
3. General Purpose: stdlib.h
4. String Functions: string.h
5. Mathematical Functions: math.h
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.