Waht is difference between strdup and strcpy?,Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher
Waht is difference between strdup and strcpy?

Some main difference b/w strdup and strcpy are given below:

1.strdup: copy a string to a location that will be created by the function. The function will allocate space, make sure that your string will fit there and copy the string. Will return a pointer to the created area. 
strdup call malloc to allocate storage. Therefor you have to call free when you are not using it.

char name[] = "Welcome";
char* copy = 0;
copy = strdup(name);

2.strcpy:copy a string to a location YOU created (you create the location, make sure that the source string will have enough room there and afterwards use strcpy to copy)
strcpy copy from source to destination without doing overflow checking.

char name[255];
strcpy(name, "Welcome");

More interview questions and answers
What are the advantages of auto variables?
What is auto variables?
Diffenentiate between an internal static and external static variable?
What are advantages and disadvantages of external storage class?
What are the characteristics of arrays in C?
When does the compiler not implicitly generate the address of the first element of an array?
What is modular programming?
What is a function and built-in function?
What is an argument ? differentiate between formal arguments and actual arguments?
What is the purpose of main( ) function?
What is a method?
What are the advantages of the functions?
What is a pointer variable?
What is a pointer ?
What is a pointer value and address?
Are pointers integers?
How are pointer variables initialized?
What is static memory allocation and dynamic memory allocation?
What is the purpose of realloc( )?
Difference between arrays and pointers?
What is difference between static and global static variable?
What are the packages in c?
How to use floodfill() function ?
What is the use of kbhit?
Write a program with out using main() function?
Constant volatile variable declaration is possible or not? if give any one example and reason.
How to print 1 to 100 without using any conditional loop?
How pointer variables are initialized ?
Does mentioning the array name gives the base address in all the integers?
Explain one method to process an entire string as one unit?
How can we check whether the contents of two structure variables are same or not?
How can we read/write structures from/to data files?
What are bit fields?
If we want that any wildcard characters in the command line argument should be approxiemately expanded , are we required to make any special provision?if yes, which?
What is the use of bit fields in a structure declaration?
What is object file?
How can you access object file?
What do the functions atoi(),itoa()and gctv()do?
How would you qsort() function to sort an array of structures?
How would you use qsort() function to sort the name stored in an array of pointers to string?
How would you use bsearch()function to search a name stored in array of pointers to string?
How to add 2 numbers without + sign?
Write a program for n lines 1 2 3 4 5 16 17 18 19 6 15 24 25 30 7 14 23 22 21 8 13 12 11 10 9
How to decide even and odd values without decision making loops?
How i can run *.bat or *.cmd file by using system function in c ?
Why does a linker error occurs for the segment: main() { extern int i; i=20; printf("%d",sizeof(i)); }
Can there be a mouse click and drag function used together to rotate a circle in c
Can there be a mouse click and drag function used in c?
What is the difference between compile time error and run time error?
How to connect a database (MS Access) to Borland C?
Waht is difference between strdup and strcpy?
What are bit fields? What is the use of bit fields in a structure declaration?
Are the variables argc and argv are local to main()?
What are enumerations?
Write down the equivalent pointer expression for reffering the same element a[i][j][k][l]?
What is the use of typedef?
Which mistakes are called as token error?
What is the function of % using in formatted string.
What is the difference between #include and #include ?file?
How to print the names of employees or students in alphabetical order using C programming?
When should we not use Quick sort as a sorting technique?
How should i rate on the basis of the basis of the scenario the insertion sort , bubble sort , Quick Sort?
What are comment line arguments in C programing?
What is the difference between null array and an empty array?
How to write a program to print its own source code?
Difference between malloc and calloc?
How much memory does a static variable takes?
What are the uses of pointers in c and c++ language?
Can we execute printf statement without using semicolan?
How to perform addition,subtraction of 2 numbers without using addition and subtraction operators?
How to write a program in c to print its own code?
What is the function of c?
what is partial class in .net 2.0
What difference between constructor and method?
Example for transient variable?
What is the difference between frame work and api? Why we called collections framework?
instanceof in Java
Is C is platform dependent or independent?how and why?
What are cookies?
What are legacy classes in java?
I want to learn java connectivity with oracle.How?
how to print this : 1 11 121 1331 14641 using for loop
I want to delete an dll with a newer version, but nothing it throws an UnauthorizedAccessException! please help!!! Assembly a = Assembly.LoadFile(source); Assembly b = Assembly.LoadFile(des
how to switch the values of two variable without using third variable?
what is the return type of delete method in StringBuffer ?
#include #include void main() { printf("%d"); getch(); }
What is a servlet ?
Can we use the constructor, instead of init(), to initialize servlet?
What is servlet context ?
What is servlet mapping?
What is session?
What Difference between GET and POST ?
What mechanisms are used by a Servlet Container to maintain session information?
What are the different ways for session tracking?
What is the difference between ServletContext and ServletConfig?
How can a servlet refresh automatically?
What is Server side push?
What is the Max amount of information that can be saved in a Session Object ?
Why should we go for inter servlet communication?
What is a output comment?