Arrays

Hey guys,


   
In this tutorial I am going to talk about arrays. In arrays we have to know that array always starts from 0.

Lets see how to access individual items or elements of arrays.

#include<stdio.h>

int main() {
  char name[18] = "Thileban Nagarasa";
  printf("My name is %s \n", name);
  
  name[2] = 'z';
  printf("My name is %s \n", name); 
  
  char food [] = "Oat meal"; {when we leave it blank it count it for us}
  printf("The best food is %s \n", food);
  
  strcpy (food{what array do you want to change?}, "bacon"{What string you want to stored it in?}); {when it string we have to use strcpy}
  printf ("The best food is %s \n", food);
}

The output is

My name is Thileban Nagarasa                                                                                                     
My name is Thzleban Nagarasa {Since it started from 0, the third letter changed.}                                                                                                    
The best food is Oat meal                                                                                                        
The best food is bacon    {now bacon is printed instead of Oat meal}

Comments