Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
So in the previous video, we've defined water swings and we talked about how to declare them as well
as we also said that strings are simply arrays of characters with a now suffix.
And in this video, we are going to talk about how can we initialize strings?
So basically, there are a couple of ways to do that.
And in some of them, there is a critical difference, which we will talk later on in this course.
But for now, let us see how we can initialize a simple array of characters.
Another string, but a simple array of characters.
So basically, we know how we can initialize a an array of characters.
Right.
We just specify the type of of this array.
The name square brackets.
And then in the curly brackets, we specify each of the elements, each of the characters in this given
array.
So these arrays called Chass Array.
That's its name.
And that's Matus Thring.
That's just an array of characters with five elements starting from index zero up to index four.
So that's okay.
And everything is great.
But how should you initialize a string?
Simply saying we just need to add a null character, a backslash zero character to the end of this array.
So one of the ways to do so, the first option to do so would be just like we've done with the characters
array.
So simply kind of initialize a character's array.
Right.
Char etr.
And just using the curly brackets, the hollow letters.
And then since it's a string, don't forget to add that now character to the end.
And now from this point on the computer will know that it can treat test ya as they string, meaning
you will be able to use different new operations and functionalities on this given string.
That basically a lot of these functionalities we are going to learn in this chapter.
OK.
So in one of the following videos, we are going to talk about different functionalities that we can
do with strings and some built-In functions and so on.
So just wait.
Guys, there is a lot of things to cover up in this section.
And before we move on.
Right.
This that was the first option to initialize a string in C.
And before we move on, I want us to take a look at another way to initialize a string.
So the second way is kind of different from the first way that we used to initialize a string.
And anything evolve the usage of double quotes.
So, for example, we can initialize a string in the second way as follows.
We simply write char, which is the type SDR in a square brackets in very similar to how we initialized
an array of characters or the first option to initialize a string.
And you can see that visually e it is this initialization is somewhat different from the first option.
But behind the scenes, what is actually going on is very similar to the first way.
This halo, which is within the double quotes, is also interpreted as a sequence of characters.
And the novel is obviously appended to the end of it because it's a string, even if you do not see
it in the initialization itself.
Like we use in the second option.
So basically the backslash zero is appended to the halo behind the scenes in the second option, like
in the first one.
So simply saying these two options to initialize the string are pretty much the same.
So we can try and initialize these examples on your own, using your own idea, and then try and print
out the contents character by character.
You already know how to do that, right?
So parse the video, initialize your strings and try to print out the content, one character after
the other.
And basically, you know how to do it.
Just use some while loop.
And as long as you didn't come to the backslash zero two the now it specifies the end of the string.
Just print one character at a time.
All right.
And once you're back, I really hope that you pause the video and try it on your own.
Now, let's take a look at a couple of other examples.
So let's, first of all, create a string for the first name and initialize it with our first name.
So in my case, my first name is Vlad, and that's how I created.
So in this way, you initialize your first name string that looks like this in the memory of your computer.
Just the letter, the characteris V L a D and a suffix of null at the end of the string.
And now let's say that you want to initialize your last name.
In my case, that's going to be a really long one.
My name is Vlad Bood Need Scheme.
So the way I initialize my last name is.
Sea land, which will be like that char, last name of of size 10.
And my last name, which is both need ski.
And the last name is said to be of size down for a reason.
We have the first nine characters which represent my last name.
And also we have to hold some space for the additional.
And of Thring indicator, the backslash zero, the null character.
So I hope that's clear why we have 10 characters instead of just the nine.
Right?
Because we are using strings and we need a space for the last now character.
And lastly, let's say that you also want to initialize a string that will hold your password.
So that will look something like this char password sized down.
And let's say that your not so you don't have so sophisticated password, which is one, two, three,
four, five, six, seven, eight, nine.
And by the way, I do not recommend you using these types of password because they are easily hacked.
So.
So now if we take a closer look and look at these password Thring, it's kind of strange.
It's kind of new, right.
Because we are using a number as a string and basically saying there is no problem because we can also
store a string of digits.
Digits also may be represented as characters.
So that's okay.
And what we've created here is a string with nine characters, and the last one is a null character,
right.
As every string in our C programming language.
And we can access any of these digits just by specifying the index itself.
And there you go.
There you have your password represented as a string.
And why do you want to store your password?
There's a string.
So one reason for that is because passwords may be may be just with numbers.
But most of the passwords include the combination between letters.
All right.
So ABC and then you go one, two, three and so on.
So it may be a combination of digits and characters and so on.
So you want to be able to store it as a string.
So this is it for these video.
I hope it's clear as to how you should initially strings now.
And just last note, I want you to know is that there is also another way, additional way that we can
initialize strings in our C programming language.
And that can be done using pointers.
And that's also very important to understand, because in this additional way, we are going to create
this string.
It's a read-only memory region.
And this way, you want to be able to modify these streambed after it was created.
But all of that, it's going to be discussed in the advanced courses and where we are going to see a
lot of different topics that also include the usage of strings, pointers, the combination between
their memory applications and so on.
So thank you guys for watching and have a great day.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.