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 |
int i; i=2; i++; if(i=4) { printf(i=4); } else { printf(i=3); } output of the program ?
Why c language is called c?
Program to display given 3 integers in ascending order
Why array is used in c?
Explain what is the best way to comment out a section of code that contains comments?
How to add two numbers without using semicolon at runtime
Explain what math functions are available for integers? For floating point?
What is pointer to pointer in c?
What is the use of f in c?
what is the meaning of 'c' language
How do you initialize pointer variables?
Dear Sir, we are required the bubble sorting programs Regs Prem