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 does typedef struct mean?

1 Answers  


Differentiate between declaring a variable and defining a variable?

1 Answers  


What is the mean of this statement:: if(int i=0 * i=9)

2 Answers   HCL,


What is a symbolic constant?

1 Answers  


What does a run-time "null pointer assignment" error mean?

2 Answers  


Please provide question papers of NATIONAL INFORMATICS CENTRE for Scientific officer

0 Answers  


What is the difference between mpi and openmp?

1 Answers  


Which command is more efficient? *(ptr+1) or ptr[1]

3 Answers  


What is array of structure in c programming?

1 Answers  


get any number as input except 1 and the output will be 1.without using operators,expressions,array,structure.don't print 1 in printf statement

3 Answers  


How to add two numbers with using function?

4 Answers  


How will you write a code for accessing the length of an array without assigning it to another variable?

1 Answers  


Categories