Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Help me following c problem using as function declaration , function call, and function definition

+6 votes
asked Sep 25, 2024 by asish sarkar (670 points)
#include<stdio.h>

int main()

{

int arr[5],i,item;

printf("enter any five element=\n");

for(i=0;i<5;i++)

{

scanf("%d",&arr[i]);

}

printf("enter the item to be searched=");

scanf("%d",&item);

for(i=0;i<5;i++)

{

if(arr[i]==item)

{

printf("%d is found in the series",item);

break;

}}

if(i==5)

{

printf("%d is not found in the series",item);

}

return 0;

}

1 Answer

0 votes
answered Sep 26, 2024 by Peter Minarik (101,340 points)

I hope the commented code below helps you understand the difference between function call, declaration, and definition.

#include <stdio.h>

// Function declaration tells the compiler what the signature of the function is,
// but it does not tell how the function works.
// A function declaration must come before any function call.
int Add(int a, int b);

// Function definition tells the compiler what exactly the function does.
// We specify the body of the function here.
// A function definition is also a function declaration.
// Function defition can be placed anywhere, it doesn't have to be before
// the function call, unless it's also your function declaration (no
// "pre-declaration" provided like above)
int Add(int a, int b)
{
    return a + b;
}

int main()
{
    int a = 2;
    int b = 3;
    int sum = Add(a, b); // This is a function call, when you provide the function name and the arguments
    printf("%d + %d = %d\n", a, b, sum); // This is also a function call, but printf is declared in stdio.h
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...