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 are the different types of control structures in programming?

666


Write a c program to demonstrate character and string constants?

1689


what are # pragma staments?

1634


If jack lies on Mon, Tue Wed and jill lies on Thursday, Friday and Saturday. If both together tell they lied yesterday. So c the given options and then c cos in the given dates one will be saying the truth and one will be lying. I got Thursday as option because jack is saying the truth he lied yest but jill is lying again as he lies on that day.

1793


When c language was developed?

644






What is the purpose of main( ) in c language?

630


How many types of operator or there in c?

609


Write the control statements in C language

658


Explain what is the difference between a free-standing and a hosted environment?

641


Is there sort function in c?

583


What are the various types of control structures in programming?

634


What is a const pointer in c?

677


What is the difference between volatile and const volatile?

573


What is integer constants?

628


What is the sizeof () operator?

628