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 |
What does typedef struct mean?
Differentiate between declaring a variable and defining a variable?
What is the mean of this statement:: if(int i=0 * i=9)
What is a symbolic constant?
What does a run-time "null pointer assignment" error mean?
Please provide question papers of NATIONAL INFORMATICS CENTRE for Scientific officer
What is the difference between mpi and openmp?
Which command is more efficient? *(ptr+1) or ptr[1]
What is array of structure in c programming?
get any number as input except 1 and the output will be 1.without using operators,expressions,array,structure.don't print 1 in printf statement
How to add two numbers with using function?
How will you write a code for accessing the length of an array without assigning it to another variable?