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

What are global variables and explain how do you declare them?

0 Answers  


What is the difference between call by value and call by reference in c?

0 Answers  


What does != Mean in c?

0 Answers  


what are the 10 different models of writing an addition program in C language?

0 Answers  


In the below code, how do you modify the value 'a' and print in the function. You'll be allowed to add code only inside the called function. main() { int a=5; function(); // no parameters should be passed } function() { /* add code here to modify the value of and print here */ }

1 Answers  






write a function for strtok()??

2 Answers   Verifone,


Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

0 Answers  


whether itis a structured language?

1 Answers   Microsoft,


write a program to fined second smallest and largest element in a given series of elements (without sorting)

9 Answers   Yahoo,


Describe the modifier in c?

0 Answers  


which one of follwoing will read a character from keyboard and store in c a)c=getc() b)c=getchar() c)c=getchar(stdin) d)getc(&c) e)none

7 Answers   Trident,


How would you rename a function in C?

0 Answers   Tech Mahindra,


Categories