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
Answers were Sorted based on User's Feedback
Answer / 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 |
Why array starts with index 0
What is the difference between text files and binary files?
How can I find out how much memory is available?
Difference between fopen() and open()?
ATM machine and railway reservation class/object diagram
What are local variables c?
change to postfix a/(b+c*d-e)
Design a program using an array that searches a number if it is found on the list of the given input numbers and locate its exact location in the list.
Write a program using two-dimensional array that lists the odd numbers and even numbers separately in a 12 input values.
What are the characteristics of arrays in c?
what is pointer ? what is the use of pointer?
Write a program to add the following ¼+2/4+3/4+5/3+6/3+... (Like up to any 12 no.s)