Character arrays and pointers - part 1

preview_player
Показать описание
See complete series on pointers in C/C++ here:

See part 2 of this lesson here:

In this lesson, we have described how we can work with character arrays using pointers. Character arrays are used to store strings in C and we work with them for all kind of string manipulation. Working with string in C is tricky and requires good understanding of pointers.

Feel free to drop your comments. feedback and suggestions.

Рекомендации по теме
Комментарии
Автор

This guy explains really well. I have a full book on pointers, but I prefer to watch his videos. Awesome C course.

keen
Автор

This whole channel is gold. Thanks. I'm watching this as I read the K&R C book.

thisaintmyrealname
Автор

The code at 14:30 works because the character array C is stored in a contiguous block of memory, so when we increased the pointer C, we were traversed through the character array C by one byte at a time, which is the amount of memory required to store a character. Once the pointer reaches the null terminator, the loop ends.

eriaardwen
Автор

I see everybody is benefiting from your teaching, and I will thank you for doing so. Great simple concise and complete explanation. Thank you

naboulsikhalid
Автор

Hi HashDLS,
Size of pointer variable will always be same whether its a pointer to int or pointer to char. Its an address right. So, It's about how many bytes we want to use to store an address. Now, this could be address of anything. In 2 bytes or 16 bits we can store max 2^16 addresses, in 4 bytes or 32 bits - 2^32. It depends upon compiler and architecture of machine. Turbo -C may be compiling for 16 bit architecture. CodeBlocks would be compiling for 32 bit architecture.

mycodeschool
Автор

14:30 works because: Since the array is passed by reference to the function, the pointer will point to the base of the array which is index 0. Then because C is passed as a char pointer, incrementing C by one will ensure traversing the array char after char since a char is 1 byte.

harunwagura
Автор

Sir you did really great job to demonstrated all concepts in very lucid way, you are rally adept, veteran teacher who delivered such complex topics in such a way to ease way to understandable

GKT
Автор

For the question at the end, I think it works because the function print(char* C) took a pointer as argument. Well, pointers can be incremented, so starting at the initial address of the string allows us to locate all the characters because they are stored contiguously in memory. Is this right? Thank you.

ozzyfromspace
Автор

You have made a superb video - many thanks.

chriswesley
Автор

I dont usually write stuff like this but your video has helped explain alot that ive had trouble with at uni. Wish I had learnt this earlier but better late then never, thanks heaps and great video

kaino
Автор

at 9:31 you said that print C2[1] will give us value l ???? But shouldn't it give us the value e ?

yashpandey
Автор

This video didn't become the top viewed in this subject for nothing . Thank you sir

mohamedatef
Автор

When printing c2[1], why is that printing out a letter? If c2 is a pointer to the address of the first character of c1, wouldn't: print c2[1]; print out 201 (the address of the second element of the array)? I could see how running: print *c2[1]; would give you 'e', but that's not what's written.

nathanbivens
Автор

awesome work sir, really appreciating, thank you 👍👍

SmartProgramming
Автор

Awesome! God bless you. Good example when you first didn't insert and then inserted null character at the end of string.

alirezaghodsipoor
Автор

You can also implement print() function like this:

void print(char *s)
{
while (*s)
printf("%c", *s++);
printf("\n");
}

tomasz-rozanski
Автор

Your videos saved my exams at university
Thank you from Greece!

sebyandrisan
Автор

you are such a great teacher, thanks a lot! your video helped me hugely!

carolinagordillo
Автор

@mycodeschool ur tutorials are simply the best. thx a lot

ceechi
Автор

These vidz are fantastic thanks for your time creating and uploading them...

steveokinevo