#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Undefined symbol display(int,int) in noname00.cpp


    Following is my code.

    Code:
    //Array passing to Function
    #include<stdio.h>
    #include<stdlib.h>
    void display(int ,int);
    void main()
    {
        int i,ar[10],n;
        printf("\n Enter the no of no's->");
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
            printf("\n Enter no->");
            scanf("%d",&ar[i]);
        }
        display(ar[10],n);
    }
    void display(int ar[10],int n)
    {
        int i;
      for(i=0;i<n;i++)
        {
            printf("\n Enter no->%d",ar[i]);
        }
        }
    It is compiling fine. But when I am pressing Ctrl-F9 to run it, I am getting this error.
    Undefined symbol display(int,int) in noname00.cpp
    where my file name is "noname00.cpp". I have tried with other file names, but no success. Please help me finding the error. Thanks.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    This
    void display(int ,int);

    Is not the same as this
    void display(int ar[10],int n)

    Change the prototype to match the definition.


    Also, if you want to pass an array to a function, it's just the array name.
    So
    display(ar[10],n);
    should be
    display(ar,n);

    Finally, main returns an int, not void.

    Edit:
    Also, since you seem to be writing C code, you should name your source files to be prog.c, not prog.cpp
    Last edited by salem; January 10th, 2013 at 09:28 AM.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo