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 c preprocessor mean?
develop algorithms to add polynomials (i) in one variable
What are the key features in c programming language?
What is the use of bitwise operator?
Write an efficient algo and C code to shuffle a pack of cards.. this one was a feedback process until we came up with one with no extra storage.
What is a stream?
What is strcpy() function?
What is the code for 3 questions and answer check in VisualBasic.Net?
What are the advantages of external class?
Write the syntax and purpose of a switch statement in C.
What is use of null pointer in c?
What is header file in c?
What does p mean in physics?
What do the functions atoi(), itoa() and gcvt() do?
What is the use of header?