String Terminator

Hey Guys, 


In this tutorial, I am going to talk about string terminator which is something happens behind the scene in C programming language. Strings are basically word or texts. Whenever you see something in quote mark in C such as printf statement. For example when you type "Thileban Nagarasa" there is always one extra string which we don't see. with that string it will look like this "Thileban Nagarasa\0".  Here this \0 is called string terminator. We always have to count this string and the spaces when we input memory storage in arrays. 

Look at this code here

#include<stdio.h>

int main() {
  char name[18]{here you have to type how many bites of memory the string is going to take up. Here you have to count the space and the string terminator. That's Why I have 18} = "Thileban Nagarasa"; {This string is a character array. array is some similar datatype. }
  printf("My name is %s \n", name);
}

This array is really useful because we can do a lot of amazing stuffs with these arrays. 

The result for this code is

My name is Thileban Nagarasa 

Comments