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 |
write a program to print sum of each row of a 2D array.
Program to display given 3 integers in ascending order
How can I find leaf node with smallest level in a binary tree?
What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }
Why c is a procedural language?
Explain what is the difference between #include and #include 'file' ?
How to reverse a linked list
1 Answers Aricent, Fidelity, IBM, TCS,
20. main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); } Answer:??????
Is it fine to write void main () or main () in c?
which will return integer? a) int*s ( ) b) ( int* ) s( ) c) int ( *s ) ( )
Between macros and functions,which is better to use and why?
List the different types of c tokens?