C Strings

A string in C is a one dimensional array of characters terminated by a null character i.e '\0'.

Declaration and Initialization
char name[] = "John";
char name[5] = "John";
char name[] = { 'J', 'o', 'h', 'n', '\0'};
char name[5] = { 'J', 'o', 'h', 'n', '\0'};


#include <stdio.h>
int main () {
   char name[5] = {'J', 'o', 'h', 'n', '\0'};
   printf("My name is: %s\n", name );
   return 0;
}


Post a Comment

0 Comments