1.

Which of the following changes can correct the program so that it prints Geeks Quiz ? #include void myStrcat(char *a, char *b) { int m = strlen(a); int n = strlen(b); int i; for (i = 0; i <= n; i++) a[m+i] = b[i]; } int main() { char *str1 = "Geeks "; char *str2 = "Quiz"; myStrcat(str1, str2); printf("%s ", str1); return 0; }

A. char *str1 = Geeks ; can be changed to char str1[100] = Geeks ;
B. char *str1 = Geeks ; can be changed to char str1[100] = Geeks ; and a line a[m+n-1] = 0 is added at the end of myStrcat
C. A line a[m+n-1] = 0 is added at the end of myStrcat
D. A line a = (char *)malloc(sizeof(char)*(strlen(a) + strlen(b) + 1)) is added at the beginning of myStrcat()
Answer» B. char *str1 = Geeks ; can be changed to char str1[100] = Geeks ; and a line a[m+n-1] = 0 is added at the end of myStrcat


Discussion

No Comment Found

Related MCQs