[source code] C Programming Tutorial - 9 - I Need Arrays

+5 Bucky Roberts · August 4, 2014

  • When you create a string, you are actually creating something called an “Array”

  • An array is just a list of items of the same data type

  • To create an array, first tell C which type of data you are storing and how many items in the list

#include <stdio.h>
#include <stdlib.h>

int main()
   char name[14] = "Bucky Roberts";
   printf("My name is %s \n", name);

   //you can access individual elements by using subscripts
   //in programming, all array start with 0, not 1
  name[2] = 'z';
  printf("My name is %s \n", name);

  //when you define an array and set its value on the same line, you don't need to say how many    elements
  char food[] = "tuna";
  printf("I love to eat %s \n", food);

  //if you want to assign a new string to an array, you have to use       strcpy()
  strcpy(food, "bacon");
  printf("I love to eat %s \n", food);

   return 0;

Post a Reply


Oldest  Newest  Rating
+2 Bucky Roberts · August 4, 2014
Yea I was thinking about this while I was making the tutorial. But it is really hard to explain an array to someone without using the word "list". 
+2 Mathias Frits Rørvik · August 4, 2014
I would not call arrays lists. When you talk about lists in C, you are usually talking about the data structure linked list.
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator