String:
- String is a one-dimensional character array.
- String is a collection symbols (alphabets, digits and special symbols).
- Strings must be represented with double quotes.
Syntax: char identity[size]; | Example: char name[20]; |
Memory representation:
- We can store only ‘n-1’ characters into an array of size ‘n’.
- Last character of every string is ‘\0’
- ASCII value of ‘\0’ character is 0.

String Format Specifier(%s):
- We use %s to read and display strings.
- To process character by character, we use %c specifier.
Program to display String:
#include<stdio.h> int main() { char str[20] = “Hello” ; printf(“%s all \n” , str); return 0; } |
strlen() : strlen() returns length of string excluding null character.
- Return type is size_t (positive integer)
- Prototype is size_t strlen(char s[]);
#include<string.h> int main() { char str[20]; size_t len; printf(“Enter string : “); gets(str); len = strlen(str); printf(“Length is : %u \n”, len); return 0; } |
Program to find the length of String without using library function:
int main() { char str[20]; size_t len=0, i=0; printf(“Enter string : “); gets(str); while(str[i] != ‘\0’){ len++; i++; } printf(“Length is : %u \n”, len); return 0; } |
Program to convert Upper case characters into Lower case in String:
#include<string.h> int main() { char src[20]; printf(“Enter Upper string : “); gets(src); strlwr(src); printf(“Lower string : %s \n”, src); return 0; } |

Program to convert Upper case characters into Lower case without Library function:
#include<stdio.h> #include<string.h> int main() { char src[20]; int i=0; printf(“Enter Upper string : “); gets(src); while(src[i] != ‘\0’) { if(src[i]>=’A’ && src[i]<=’Z’) { src[i] = src[i]+32; } i++; } printf(“Lower string : %s \n”, src); } |
Program to reverse the String without using Library function:
#include<string.h> int main() { char src[20], temp; int i, j; printf(“Enter string : “); gets(src); i=0; j=strlen(src)-1; while(i<j) { temp = src[i]; src[i] = src[j]; src[j] = temp; i++; j–; } printf(“Reverse string : %s \n”, src); } |