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 is a string?

0 Answers  


Given a piece of code int x[10]; int *ab; ab=x; To access the 6th element of the array which of the following is incorrect? (A) *(x+5) (B) x[5] (C) ab[5] (D) *(*ab+5} .

2 Answers   Oracle,


What is FIFO?

0 Answers  


What is the difference between a function and a method in c?

0 Answers  


What are the 5 organizational structures?

0 Answers  






What is the sizeof () a pointer?

0 Answers  


Explain what are compound statements?

0 Answers  


What are comments and how do you insert it in a C program?

0 Answers  


suppose there are five integers write a program to find larger among them without using if- else

2 Answers  


Give the output for the following program. #define STYLE1 char main() { typedef char STYLE2; STYLE1 x; STYLE2 y; clrscr(); x=255; y=255; printf("%d %d\n",x,y); }

2 Answers   ADITI,


main() { int x, arr[8]={11,22,33,44,55,66,77,88}; x=(arr+2)[3]; printf(ā€œ%dā€,x); }

8 Answers   Vector,


send me the code of flow chart generator using C-programming language amd this code should calculate the time and space complexity of the given progran and able to generate flowchart according to the given program?

0 Answers   TCS,


Categories