tags:

views:

148

answers:

3
#include<stdio.h>
main( )
{ int num[ ] = {24, 34, 12, 44, 56, 17};
 dislpay(&num[0],6); 
}
display ( int *j, int n ) 
{
int i ;
for ( i = 0 ; i <= n - 1 ; i++ )
 { 
  printf ( "\nelement = %d", *j ) ; 
  j++ ; /* increment pointer to point to next element */ 
    }
}

The language is c, windows vista using visual c++ 2005 express.

A: 

Typo line 4, dislpay -> display?

Gabe
...I'm just saying, given the info by the poster this is the best I could give.
Gabe
The lack of return types could be a problem too.
FrustratedWithFormsDesigner
Oh, this *does* look like homework! And the only other post he has on SO is homework too! KHAAAAAAN!
Gabe
+2  A: 

The correct code should be something like :

 #include<stdio.h>

 void display(int*, int); //declaration of your function 

 int main( ) //return type of main should be int
 {
      int num[ ] = {24, 34, 12, 44, 56, 17};
      display(&num[0],6);  //Correct the spelling mistake
 }
 void display ( int *j, int n ) //specify a return type
 {
     int i ;
     for ( i = 0 ; i <= n - 1 ; i++ )
     { 
            printf ( "\nelement = %d", j[i] ) ; 

     }
 }
Prasoon Saurav
Why a downvote?
Prasoon Saurav
@Prasoon Saurav - you marked this as community wiki, so any votes will not effect your rep.
Oded
If your gonna have non-void return in main( ) you should at least `return 0;` . I didn't down vote you though, looks like proper solution.
wfoster
For being too right. ;) Whether this is homework or learning C, aja will learn more effectively if we don't do it for him.
dublev
@Oded : I know that but I was surprised to see my answer getting a downvote even though it is perfectly correct.
Prasoon Saurav
@wfoster : Nopes! In C99, explicit `return 0;` is optional.
Prasoon Saurav
@dublev : Thats why I intentionally made my post community wiki because I did not want any reputation point for this answer. :-)
Prasoon Saurav
@Prasoon: Ooops, just let my rookie-status be known :)
wfoster
Random downvotes happen all the time, don't take them to heart. Sometimes you will get an answer (which you may or may not agree with), sometimes you won't even get that.
Oded
A: 

The reason you're getting an error, besides your typo, is that in C, you cannot refer to a variable or function before its declaration. Thus you can fix your code by either moving the display function to before main, or as Prasoon did, add a declaration above main.

Technically you can leave out return types as C assumes int (at least ANSI C89 does), but it's not a good idea. It's good practice to always specify return type to improve readability and avoid tricky type-mismatch bugs (especially since C does a lot of implicit casting).

Aidan