[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

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;
}

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 :: TCS Sopra Steria

Post Your Answer Here:     

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here