C Programming Tutorial – 45 – Strings and Pointers

Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts


Nepeta Leijon says:

Since movie2 is a pointer, why do you not need to dereference it to change the value? Shouldn’t it be changing the memory address instead? :/

Roger Nevez says:

fonts too small

Anthony Halim says:

I tried printf(“%p”, *movie2); and it gives me some seemingly random number that does not match he ASCII number of the first letter of the array. Would someone explain to me what is happening here ._.

edit :
printf(“%s”, *movie2); will crash the programme,
printf(“%d”, *movie2); gives ASCII code of the first letter of the array.

msbtrock says:

It’s always important to NULL terminate your string.  A video showing what happens when a person fails to do so is worth making, in my professional c/c++/C# opinion. Cheers and salutations, from Seattle.

I’d think you learn more if you used the c++ string class (in c++) or implemented a similar data structure (in c). the added functionality provides an easier way to bind functions with data (in this case a string) and to have instant ability to modify data and It will also improve readability. You can do a quick swap that way, and still use puts to print the string. Adding a call of malloc (new in c++) let’s character arrays exist off the stack (to be specific, the string’s data will be in the heap, the pointer may still be on the stack). All of your code is running a tab bit slower than it would if you had allocated from the heap, when it comes to data modification during realtime. Which doesn’t seem like much but if you wanted to have 2gb of strings in your game you’d crash if you used static strings or if you need to swap strings of the same length (static strings sit on a string table, which is limited based on the OS). Nothing wrong with using a character array or static string but we need to remember that we as c programmers need to leave the call stack as empty as possible. Placing the string’s data at the heap memory it will allow for more strings. the only downside is you lose size(char*) (4 bytes on 32 bit machines) per string but what you gain is the ability to create larger strings and to do a bunch of other hacks. C have no ZERO error checking for strings so if you happen to write past your NULL (which you can) you’ll print out erogenous data from your stack or heap when using calloc or new. Though some compilers will protect you by spacing out RAM with extra NULLS this isn’t guaranteed. Which makes debugging strings very difficult; which is why the C++ style of using dynamic memory allocation is better. I also believe the max size of a static string is the size of the string pool but that will crash your program when you jump into a new scope that has their own string pool. (for the layman, use new/calloc/malloc attached to char * to the size of the amount of elements + 1 (space for NULL)). I’ll add that Calloc is a great way to insure your data is NULL terminated but I never seem to use it…. Thanks again, I’m just trying to add to the conversation. Please don’t take it personal or anything like that

Vesna Bozovic says:


Wendy Avalos says:

c strings are such a trip. why??

John Hurley says:

I learned today that Bucky was wrong about something in this video. An array is not a POINTER to the memory address of the first element; it IS the memory address of the first element.

istainblack says:

it’s 3 AM in morning .. physics student ? ?

il2xbox says:

why were you making this at 2:09 AM

Duarte Castanho says:

When I write:
movie2 = “New movie title”;

Am i chanching what is in moive2 adress, or i’m allocating a new piece of memory for “New movie title”?

ManiProgrammingAndAnimation says:

Awesome lesson! I have an example of how to use pointers to input strings on my channel if anyone needs help!

Aly Ahmed says:

what does it mean to have a char variable(or constant as you clarified) with empty square brackets next to it?
(e.g: movie1[]= whatever)

AJay Gupta says:

why movie2 dont have square brackets after it ??

Vishal Goel says:

pointers are weird.

le00 says:

Thank you!

mahendra pratap jewaria says:

it’s 2 AM in morning .. enginner student ? ?

videovulcan says:

Bucky learns himself by reading books while pooping, he has a whole bookcase full of programming and science. I wounder how many languages stay in his head. Surely he must get rusty. I get forgetful with certain functions in a programming language if I haven’t used it for a while.

Agustin Escoto says:

How would you store a string into the array using only pointers. That is without this -> array[i]

Zayani Meriam says:

so complicated 🙁

Jun Jet T says:

Bucky made this video at 2 am…

jyoti Singh says:

please increase font size please

Stephan Kerbl says:

Is this safe to use? What happens to the spare memory addresses of the original movie2 after reassigning the new string? Do the get deallocated? Or are they still there, but don’t get read behind the new character. You could still access them by incrementing the pointer past the new , right?

Likewise, what would happen if the new string had, say, 200 characters?

Waqar-un-nisa Nabi says:

For a while I thought you were pronouncing “him” as “ham” XD Thanks for these videos on pointers 😀 Really helped a lot in my understanding.

Knight Nobody says:

HI there +Bucky Roberts   I know you are busy but could you pls restart the 3DS max tutoriuls I love all your tutoriuls and you are the best teacher here on youtube better then my teachers from school 😀

Sharmin Fariha says:

Can’t see properly even with 1080p! can’t you provide a more clearer screen as you did in some python tutorials? Please!

TcopRulz says:

so if i do it within a loop and repeatedly assign new values to movie2, will i end up with an “out of memory message” or something similar?

Gova Murali says:

why cant i print out the first string in an array of pointer using this statement:


int main()
char *names[]={“Bowzer”,”santa”};


if i try this,it works though:

int main()
char *names[]={“Bowzer”,”santa”};


Edio Ilha says:

Thank you so much!! For all your videos!!

Ashkan Abedian says:

Bucky are you a software programmer? if yes how much money do you make a year? and do you recommend it as a career path?

Jane You says:

could you make a program explaining matrix multiplication. 

r00t hkr says:

Please tell me you DO know (or at least lie) who created C…, if you don’t you might need to do some history my friend.

Alex Todoran says:

Fuck pointers.

Irteza asad says:

so it’s gonna start printing any string i’s pointing to……………………that’s great!!

ujjawal patel says:

before you talk .. please enlarge your fonts in your editor .. if possible..

Amritpal S. says:

In memory, after assigning “movie2” new content what happens to the content which was assigned earlier to “movie2”? Is the new content replaced in the same memory location or a new memory address is assigned to movie2?

πένε says:

I could never get mad at Dennis Ritchie

FlipFlop says:

Can you typecast the array and then change it that way?

Arifin Firdaus says:

Wow, your are pretty damn awesome! thanks Bucky!!

Gerald Shqau says:

The font is way too small. Please fix it. Im my phone I can barely read anything

Anne Elrod says:

Why did it just cut off mid-sentence like that?

Quốc Vương Hồ says:

oh u did the tutorial at 2 AM @@

That’s what we call “night owl”

 Write a comment


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!