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 union in c?
List some basic data types in c?
1.int a=10; 2.int b=20; 3. //write here 4.b=30; Write code at line 3 so that when the value of b is changed variable a should automatically change with same value as b. 5.
What are the advantages of using new operator as compared to the function malloc ()?
Where can I get an ansi-compatible lint?
what do you mean by inline function in C?
How can I prevent another program from modifying part of a file that I am modifying?
What does the c preprocessor do?
What is structure pointer in c?
What is malloc calloc and realloc in c?
In C language, a variable name cannot contain?
Write a code to generate a series where the next element is the sum of last k terms.
How do you use a 'Local Block'?
When should volatile modifier be used?
What is structure in c definition?