Thread: Print the array element error in program

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    99

    Print the array element error in program

    I was trying to write program where I want to print array element

    Code:
    #include <stdio.h>
    int main (void)
    {
     unsigned i, array[5] = {1,2,3,4,5};
     
     for (i = 0, i < 5; i++)
     {
      printf(" Print array element : %d  \n", array[5])
     }
    
     
     return 0;
    }
    compiler show error

    hello.c:8:24: error: expected ';' before ')' token
    for (i = 0, i < 5; i++)
    ^
    hello.c:11:2: error: expected ';' before '}' token
    }

    if I use array [5]
    then
    Print element of array : 0
    Print element of array : 1
    Print element of array : 2
    Print element of array : 3
    Print element of array : 4

    I don't understand why there is array [5] only ?
    Last edited by vead; 01-04-2018 at 11:16 PM. Reason: if i put array [i] get error but when i put array [5] I don't see error

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Insert element after the last element in array in c
    By amaturequestion in forum C Programming
    Replies: 3
    Last Post: 04-09-2015, 08:29 AM
  2. Replies: 2
    Last Post: 08-25-2011, 08:30 AM
  3. Replies: 2
    Last Post: 05-23-2011, 02:04 PM
  4. how to print/access the 1st element of the first set of the vector
    By kapil1089thekin in forum C++ Programming
    Replies: 1
    Last Post: 08-11-2010, 02:28 PM
  5. get the largest element from the array and print it
    By casperghost in forum C Programming
    Replies: 2
    Last Post: 12-27-2009, 06:22 PM

Tags for this Thread