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


Please Help Members By Posting Answers For Below Questions

What is the sizeof () operator?

831


Differentiate between static and dynamic modeling.

887


Are there any problems with performing mathematical operations on different variable types?

839


Is main a keyword in c?

877


What does the error message "DGROUP exceeds 64K" mean?

1020


What is a newline escape sequence?

898


What does *p++ do? What does it point to?

852


What is ctrl c called?

824


Explain what’s a signal? Explain what do I use signals for?

832


Why is structure important for a child?

867


How is null defined in c?

909


How do I send escape sequences to control a terminal or other device?

873


Write a code on reverse string and its complexity.

820


How main function is called in c?

878


What is a dynamic array in c?

865