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 are the different types of control structures in programming?
Write a c program to demonstrate character and string constants?
what are # pragma staments?
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.
When c language was developed?
What is the purpose of main( ) in c language?
How many types of operator or there in c?
Write the control statements in C language
Explain what is the difference between a free-standing and a hosted environment?
Is there sort function in c?
What are the various types of control structures in programming?
What is a const pointer in c?
What is the difference between volatile and const volatile?
What is integer constants?
What is the sizeof () operator?