Strings


  • The way a group of integers can be stored in integer array , Similarly a group of character can be stored in character array.
    character array many times also called strings. Many languages internally treat string as a character array but conceal the fact from the programmer.
  • A String constant is a one-dimensional array of character terminated by a null ('\0') character .
    eg.char country={ 'U' , 'S' , 'A' , '\0' } ;
  • Each character occupies one byte of memory address and the last character is always '\0'. '\0' may look likes two character but but it is a single character. it is called NULL character.Note that 0 and \0 are not same.Ascii value of 0 is 48 and \0 is just a null.
  • '\0' is important because it is only way to know where string ends.

#include<stdio.h>
	void main(){
		 char name[]="CTUTORIAL";
		 int i=0;
		 
		 while(i<=9){
			printf("%c",name[i]);
		 }
		 printf("\n");
		 
	}

Output:


CTUTORIAL



  • Print Page