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 |
How many levels deep can include files be nested?
What are runtime error?
Write code for initializing one dimentional and two dimentional array in a C Program?
5 Answers Deshaw, Edutech, GMD,
44.what is the difference between strcpy() and memcpy() function? 45.what is output of the following statetment? 46.Printf(“%x”, -1<<4); ? 47.will the program compile? int i; scanf(“%d”,i); printf(“%d”,i); 48.write a string copy function routine? 49.swap two integer variables without using a third temporary variable? 50.how do you redirect stdout value from a program to a file? 51.write a program that finds the factorial of a number using recursion?
how 2 compile & execute c program with out using editor?
What is pointer & why it is used?
What is keyword in c?
what is the difference between postfix and prefix unary increment operators?
what is c programming?
Write a C program that computes the value ex by using the formula ex =1+x/1!+x2/2!+x3+3!+………….
WRITE A PROGRAM TO PRINT THE FOLLOWING OUTPUTS USING FOR LOOPS. A) * B) ***** *** * * ***** * * *****
What is the diffrent between while and do while statement ?