C strcat() method

This function concatenates (appends) one string to the end of another string.

Syntax:


strcat(str1, str2); 

Parameters:

  • str1 is a first string
  • str2 is a second string

Return Value:

  • It returns add of first string to second string.

Note: Make sure the str1 string has enough space to hold both the original string and the appended string.

Example:


#include <stdio.h>
#include <string.h>

int main() {
    char str1[10] = "My";
    char str2[] = " World";
    
    strcat(str1, str2);
    printf("Concatenated string: %s\n", str1);  // Output: My World
    
    return 0;
}

Output:

Concatenated string: My World

C strcat() method – Interview Questions

Q 1: What does strcat() do?
Ans: It appends one string to the end of another.
Q 2: What is the syntax of strcat()?
Ans: strcat(destination, source);
Q 3: Should destination have extra space?
Ans: Yes, to hold the combined string.
Q 4: Which header file is required for strcat()?
Ans: .
Q 5: Is strcat() safe to use?
Ans: No, it does not prevent buffer overflow.

C strcat() method – Objective Questions (MCQs)

Q1. What does strcat() do in C?






Q2. What is the correct syntax of strcat()?






Q3. Which header file is required for strcat()?






Q4. What happens if the destination array does not have enough space for strcat()?






Q5. What will be the output of this code?

char src[] = "Hello";
char str2[] = "World";
strcat(str1, str2);
printf("%s", str1);






Related C strcat() method Topics