|
INTERVIEW QUESTIONS
C
STRINGS IN C
DETAILS
Question: Tell me the difference between strdup and strcpy?
Answer: strcpy will not allocate the memory for the copy for you, which means you have to give it not only the pointer to the string to copy, but also a pointer to the place to copy it to, which you have set up yourself. strdup will grab itself a place to copy the string to, which you will have to free up later when you don't need the copy anymore.
|
|
|
Category |
Strings in C Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 7897 users |
Added on |
3/18/2013 |
Views |
71769 |
Rate it! |
|
|
Question:
Tell me the difference between strdup and strcpy?
Answer:
strcpy will not allocate the memory for the copy for you, which means you have to give it not only the pointer to the string to copy, but also a pointer to the place to copy it to, which you have set up yourself. strdup will grab itself a place to copy the string to, which you will have to free up later when you don't need the copy anymore. Source: CoolInterview.com
Answered by: kishore | Date: 6/29/2008
| Contact kishore
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 |
|
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
|
|
How to type a string without using printf function?
|
View Answer
|
|
What is the difference between System.String and System.StringBuilder classes?
|
View Answer
|
|
What is the advantage of using System.Text.StringBuilder over System.String?
|
View Answer
|
|
What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
|
View Answer
|
|
How can I convert a number to a string?
|
View Answer
|
|
How can I convert a string to a number?
|
View Answer
|
|
How do you print only part of a string?
|
View Answer
|
|
What is the difference between a string and an array?
|
View Answer
|