C Programming :: Dynamic Memory Allocation - Discussion
Home > C Programming > Dynamic Memory Allocation > MCQs Questions Discussion
13 / 18
What will be result of the following program?
#include<stdio.h>
#include<malloc.h>
int myalloc(char *x, int n){
x= (char *)malloc(n*sizeof(char));
memset(x,\0,n*sizeof(char));
}
int main(){
char *g="String";
myalloc(g,20);
printf("The string is %s",g);
return 0;
}
#include<stdio.h>
#include<malloc.h>
int myalloc(char *x, int n){
x= (char *)malloc(n*sizeof(char));
memset(x,\0,n*sizeof(char));
}
int main(){
char *g="String";
myalloc(g,20);
printf("The string is %s",g);
return 0;
}
ARun time error/Core dump
BThe string is: String
CThe string is: Oldstring
DSyntax error during compilation
ENone of these
Answer: Option (Login/Signup)
Show Explanation
in this program char pointer g is passed instead of address of it. so that memset in myalloc will not impact.
Because of it, it will print The string is String.
Asked In ::
STEP-BY-STEP
It will print The string is: String .
in this program char pointer g is passed instead of address of it. so that memset in myalloc will not impact.
Because of it, it will print The string is String.
Read Full Answer
Report Error
Please Login First Click Here