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
Why isnt there a numbered, multi-level break statement to break out
What is the general form of #line preprocessor?
Tell us bitwise shift operators?
in linking some of os executables are linking name some of them
What is string constants?
What is the use of clrscr?
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.
What is the use of linkage in c language?
Do pointers store the address of value or the actual value of a variable?
Can main () be called recursively?
Why do we use null pointer?
What is an example of structure?
p*=(++q)++*--p when p=q=1 while(q<=6)
Synonymous with pointer array a) character array b) ragged array c) multiple array d) none
What is the use of volatile?