why this is not working

0 chinesh doshi · August 21, 2015
#include <stdio.h>
#include <stdlib.h>
void display(int* , int)
int main()
{
    int num[] = {24,34,59,68,78};
    display(&num[0],5);
    return 0;
}
void display(int*j , int n)
{
    int i;
    for(i=0 ; i<=n-1;i++)
    {
        printf("element = %d \n" , *j);
        j++;
    }
}

Post a Reply

Replies

Oldest  Newest  Rating
0 chinesh doshi · August 28, 2015
okkk
0 Florin Nastase · August 28, 2015
I think this should work:


#include
#include

void display(int*, int);  // here you forgot to put ';'

int main()
{
    int num[] = {24, 34, 59, 68, 78};
    display(&num[0], 5);

    return 0;
}

void display(int* j, int n)
{
    int i;
    for(i = 0; i
0 chinesh doshi · August 21, 2015
doing so does not make any sense :(
+1 c student · August 21, 2015
arrays are by default passed in by reference.
display (num, 5);
  • 1

C

107,190 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator