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 |
Difference between strcpy() and memcpy() function?
When can you use a pointer with a function?
Toggle nth bit in a given integer - num
Is sizeof a keyword in c?
Find the O/p of the following 1) #include int main() { char c='1'; int j=atoi(c); }
How can you pass an array to a function by value?
Which of the following sorts is quickest when sorting the following set: 1 2 3 5 4 1) Quick Sort 2) Bubble Sort 3) Merge Sort
Explain how can you determine the size of an allocated portion of memory?
What are the different types of errors?
main() { int i; printf("%d", &i)+1; scanf("%d", i)-1; }
What are structure members?
What is structure pointer in c?