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

Why isnt there a numbered, multi-level break statement to break out

592


What is the general form of #line preprocessor?

592


Tell us bitwise shift operators?

601


in linking some of os executables are linking name some of them

1655


What is string constants?

664






What is the use of clrscr?

602


Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.

656


What is the use of linkage in c language?

619


Do pointers store the address of value or the actual value of a variable?

613


Can main () be called recursively?

633


Why do we use null pointer?

609


What is an example of structure?

591


p*=(++q)++*--p when p=q=1 while(q<=6)

1271


Synonymous with pointer array a) character array b) ragged array c) multiple array d) none

622


What is the use of volatile?

614