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 is structure in c explain with example?
Explain what are the advantages and disadvantages of a heap?
triangle number finding program...
Write a program to generate the Fibinocci Series
what is ans for this scanf(%%d",c);
Unsigned char c; for ( c=0;c!=256;c++2) printf("%d",c); No. of times the loop is executed ?
What are the usage of pointer in c?
do you think its fraud or original company?
There is a mobile keypad with numbers 0-9 and alphabets on it. take input of 7 keys and then form a word from the alphabets present on those keys.
How do we print only part of a string in c?
What is && in c programming?
How do we open a binary file in Read/Write mode in C?