|
INTERVIEW QUESTIONS
C
STRINGS IN C
DETAILS
Question: What is the difference between strings and character arrays ?
Answer: A major difference is: string will have static storage duration, whereas as a character array will not, unless it is explicity specified by using the static keyword.
Actually, a string is a character array with following properties:
* the multibyte character sequence, to which we generally call string, is used to initialize an array of static storage duration. The size of this array is just sufficient to contain these characters plus the terminating NUL character.
* it not specified what happens if this array, i.e., string, is modified.
* Two strings of same value[1] may share same memory area. For example, in the following declarations:
char *s1 = “Calvin and Hobbes”; char *s2 = “Calvin and Hobbes”;
the strings pointed by s1 and s2 may reside in the same memory location. But, it is not true for the following:
char ca1[] = “Calvin and Hobbes”; char ca2[] = “Calvin and Hobbes”;
[1] The value of a string is the sequence of the values of the contained characters, in order.
|
|
|
Category |
Strings in C Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 8138 users |
Added on |
9/18/2014 |
Views |
71487 |
Rate it! |
|
|
Question:
What is the difference between strings and character arrays ?
Answer:
A major difference is: string will have static storage duration, whereas as a character array will not, unless it is explicity specified by using the static keyword.
Actually, a string is a character array with following properties:
* the multibyte character sequence, to which we generally call string, is used to initialize an array of static storage duration. The size of this array is just sufficient to contain these characters plus the terminating NUL character.
* it not specified what happens if this array, i.e., string, is modified.
* Two strings of same value[1] may share same memory area. For example, in the following declarations:
char *s1 = “Calvin and Hobbes”; char *s2 = “Calvin and Hobbes”;
the strings pointed by s1 and s2 may reside in the same memory location. But, it is not true for the following:
char ca1[] = “Calvin and Hobbes”; char ca2[] = “Calvin and Hobbes”;
[1] The value of a string is the sequence of the values of the contained characters, in order. Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
What is the difference between strings and character arrays ?
|
View Answer
|
|
Write to program to accept any number upto 7 digits and convert this number into words like this e.g. 25525 :- twenty five thousands five hundred twenty five.
|
View Answer
|
|
Explain one method to process an entire string as one unit?
|
View Answer
|
|
How would you implement a sbstr()function that extract a sub string from a givn string?
|
View Answer
|
|
How do you print a string on the pointer?
|
View Answer
|
|
Why doesn’t strcat (string, ‘!’); work ?
|
View Answer
|
|
How can i print a’%’ character in a print format string?
|
View Answer
|
|
Tell me the difference between strdup and strcpy?
|
View Answer
|
|
Write a C program that will convert Simple Sentence to Complex/Compound Sentence.
|
View Answer
|
|
If a string variable contain "i am a good boy" then how a c program will print "boy good a am i".?
|
View Answer
|
|
How do I use c-strings to write a c program that Removes multiple spaces between words in a paragraph?
|
View Answer
|
|
How to get string in files and print the string in the reverse order?
|
View Answer
|
|
How can I convert a number to a string?
|
View Answer
|
|
i need a code in c for strings and general, which are important and frequently asked in programming test especially for SUBEX.
|
View Answer
|
|
What is the difference between a string and an array?
|
View Answer
|
|
How can I convert a number to a string?
|
View Answer
|
|
Following declarations are different from one another const char *const s; char const *const s;
|
View Answer
|
|
Can we use string in switch statement?
|
View Answer
|
|
What is wrong with the following c program? char *s1 = "hello"; char *s2 = "world"; char *s3 = strcat(s1, s2);
Please provide me explanations??
|
char *s2 = "world"; char *s - Strings in C Interview Questions & Answers">
View Answer
|
|
Write a program which accepts a filename as a command line argument and coverts all characters in the file to uppercase.
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All Strings in C Interview Questions & Answers - Exam Mode /
Learning Mode
|