[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

491 / 18

What will the following program do?

#include<stdio.h>
#include<string.h>
#include<malloc.h>
int main(){
int i;
char a[]="String";
char *p="New Sring";
char *Temp;
Temp=a;
a=malloc(strlen(p) + 1);
strcpy(a,p); //Line no:9//
p = malloc(strlen(Temp) + 1);
strcpy(p,Temp);
printf("(%s, %s)",a,p);
free(p);
free(a);
return 0;
} 

Chose correct option

ASwap contents of p and a and print

BGenerate compilation error in line number 8

CGenerate compilation error in line number 5

DGenerate compilation error in line number 7

EGenerate compilation error in line number 1

Answer: Option (Login/Signup)

Show Explanation

malloc allocation need to be assigned to char pointer instead of char array. a=malloc(strlen(p) + 1);


Asked In :: TCS

Post Your Answer Here:     

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here