C PROGRAMMING
MULTIPLE CHOICE QUESTION
OLD QUESTION BANK
SAMPLE QUESTION 2080 AND SOLUTION

Definition :

A string is a sequence of characters stored in an array of characters terminated by a null character ('\0'). 

 

 

Syntax: 

char string_name[size];

 

Declaration and initialization of a String

 

char str[50] = "Hello, World!";

 

Example program to read and print string 

#include <stdio.h>

int main()

{

    char name[20];

    printf("Enter name: ");

    gets(name);

    printf("Your name is %s.", name);

    return 0;

}

String Functions:

C provides several built-in functions in the string.h library to perform operations on strings. Some commonly used functions include:

  • strlen(): Returns the length of a string.
  • strcpy(): Copies one string to another.
  • strcat(): Concatenates two strings.
  • strcmp(): Compares two strings.
  • strchr(): Searches for a character in a string.
  • strstr(): Searches for a substring in a string.