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



What will be result of the following program? void myalloc(char *x, int n) ..

Answer / vijoeyz

Run time error/Core dump.

Is This Answer Correct ?    5 Yes 0 No

What will be result of the following program? void myalloc(char *x, int n) ..

Answer / v.prasad

a)the string is string

Is This Answer Correct ?    0 Yes 1 No

What will be result of the following program? void myalloc(char *x, int n) ..

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

Post New Answer

More C Interview Questions

write a program to print sum of each row of a 2D array.

4 Answers  


Program to display given 3 integers in ascending order

1 Answers   N Tech,


How can I find leaf node with smallest level in a binary tree?

1 Answers  


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'); }

0 Answers   Wilco,


Why c is a procedural language?

0 Answers  






Explain what is the difference between #include and #include 'file' ?

0 Answers  


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:??????

2 Answers  


Is it fine to write void main () or main () in c?

0 Answers  


which will return integer? a) int*s ( ) b) ( int* ) s( ) c) int ( *s ) ( )

1 Answers   C DAC,


Between macros and functions,which is better to use and why?

0 Answers  


List the different types of c tokens?

0 Answers  


Categories