C | String | Question 16

Output of following C program? Assume that all necessary header files are included

filter_none

edit
close

play_arrow

link
brightness_4
code

int main()
{
    char *s1 = (char *)malloc(50);
    char *s2 = (char *)malloc(50);
    strcpy(s1, "Geeks");
    strcpy(s2, "Quiz");
    strcat(s1, s2);
    printf("%s", s1);
    return 0;
}

chevron_right


(A) GeeksQuiz
(B) Geeks
(C) Geeks Quiz
(D) Quiz


Answer: (A)

Explanation: strcpy puts \0 at the end.

strcat starts from \0, concatenates string and puts \0 at the end.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.