What will be result of the following program?
void myalloc(char *x, int n)
{
x= (char *)malloc(n*sizeof(char));
memset(x,\0,n*sizeof(char));
}
main()
{
char *g="String";
myalloc(g,20);
strcpy(g,"Oldstring");
printf("The string is %s",g);
}
a) The string is : String
b) Run time error/Core dump
c) The string is : Oldstring
d) Syntax error during compilation
e) None of these
Answers were Sorted based on User's Feedback
Answer / rishabh taneja
correct the line: memset(x,\0,n*sizeof(char)); as
memset(x,'\0',n*sizeof(char));
Result(if the line mentioned is corrected):
The string is: Oldstring
The result is verified by me by actually running it.
| Is This Answer Correct ? | 0 Yes | 2 No |
What is a MAC Address?
What is an lvalue and an rvalue?
what is the difference between exit() and _exit() functions?
What does. int *x[](); means ?
What is information technology.
There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?
What is a program flowchart?
How will you delete a node in DLL?
Why ca not I do something like this?
Why shouldn’t I start variable names with underscores?
What is console in c language?
Are negative numbers true in c?