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

int i; i=2; i++; if(i=4) { printf(i=4); } else { printf(i=3); } output of the program ?

15 Answers   Mascot,


Why c language is called c?

0 Answers  


Program to display given 3 integers in ascending order

1 Answers   N Tech,


Why array is used in c?

0 Answers  


Explain what is the best way to comment out a section of code that contains comments?

0 Answers  






How to add two numbers without using semicolon at runtime

2 Answers  


Explain what math functions are available for integers? For floating point?

0 Answers  


What is pointer to pointer in c?

0 Answers  


What is the use of f in c?

0 Answers  


what is the meaning of 'c' language

3 Answers  


How do you initialize pointer variables?

0 Answers  


Dear Sir, we are required the bubble sorting programs Regs Prem

1 Answers  


Categories