Computer Science, asked by sachinkumar6980, 1 year ago

In c programming, if we need to store word "india" then syntax is as below – char name[]; name = "india". Explain the ans why correct or other why are wrong

Answers

Answered by Kenblock43
2

Answer:

A string in C is actually a character array. As an individual character variable can store only one character, we need an array of characters to store strings. Thus, in C string is stored in an array of characters. Each character in a string occupies one location in an array. The null character ‘\0’ is put after the last character. This is done so that program can tell when the end of the string has been reached. For example, the string “Hello” is stored as follows. enter image description here

Since the string contains 5 characters. it requires a character array of size 6 to store it. the last character in a string is always a NULL('\0') character. Always keep in mind that the '\0' is not included in the length if the string, so here the length of the string is 5 only. Notice above that the indexes of the string starts from 0 not one so don't confuse yourself with index and length of string.

Explanation:

please mark this answer as brilliant

Answered by KajalBarad
0

Answer:

Yes, The code snippet is correct

Explanation:

C uses char type to store characters and letters. However, the char type is integer type because underneath C stores integer numbers instead of characters.In C, char values are stored in 1 byte in memory,and value range from -128 to 127 or 0 to 255.

When strings are declared as character arrays, they are stored like other types of arrays in C. For example, if str[] is an auto variable then string is stored in stack segment, if it’s a global or static variable then stored in data segment, etc.

Similar questions