Posted By:
11 Jun, 2013 12:17 am PDT

strings in C and C++

what are strings and how do we use them in c programming?

String is an array of characters stored in some place in the memory and are treated as values for variables. Please watch the video for details....
Was it useful?  

Strings are a collection of characters.

Strings are placed between "quotes".

By default , a null character is stored at the end of every string that tells that compiler that it is the end of string.

Strings are declared in C in similar manner as arrays. Only difference is that, strings are of char datatype.In C, string can be initialized in different number of ways.

char s[]="abcd";


char s[5]="abcd";

Most used functions in Strings are :

strlen() Calculates the length of string
strcpy() Copies a string to another string
strcat() Concatenates(joins) two strings
strcmp() Compares two string
strlwr() Converts string to lowercase
strupr() Converts string to uppercase


Please have a look at the following code to understand better.

#include <stdio.h>
#include <string.h>
int main(){
    char a[20]="Program";
    printf("Length of string a=%d \n",strlen(a));
    return 0;


Was it useful?  

Please login to reply to this problem.