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
Answer Posted / 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 |
Post New Answer View All Answers
What is the sizeof () operator?
Differentiate between static and dynamic modeling.
Are there any problems with performing mathematical operations on different variable types?
Is main a keyword in c?
What does the error message "DGROUP exceeds 64K" mean?
What is a newline escape sequence?
What does *p++ do? What does it point to?
What is ctrl c called?
Explain what’s a signal? Explain what do I use signals for?
Why is structure important for a child?
How is null defined in c?
How do I send escape sequences to control a terminal or other device?
Write a code on reverse string and its complexity.
How main function is called in c?
What is a dynamic array in c?