what is the difference between procedure and functions??

Dani AI

Generated

Short answer: "procedure" is a name some languages use for a subroutine that does not return a value; "function" usually returns a value. C does not have a separate "procedure" keyword — C only has functions. A C function with return type void is the practical equivalent of a procedure in other languages.

Think in terms of semantics, not syntax. A function returns data; a procedure performs actions (side effects). When designing C code prefer functions that produce clear results and keep side effects explicit. For multiple outputs, return a struct or use output parameters via pointers and document ownership and null checks.

Example patterns (C-style):

int add(int a, int b) {
    return a + b;
}

void log_sum(int a, int b) {
    printf("%d\n", a + b);
}

void divide(int a, int b, int *quotient, int *remainder) {
    if (b == 0) return; /* handle error properly in real code */
    *quotient = a / b;
    *remainder = a % b;
}

Practical cautions: a non-void function must return a value on every control path (otherwise behavior is undefined). Use void when no result is intended, but remember that a void function still returns control to the caller. As pointed out, the terminology differs by language; 's suggestion to search for references is sensible if deeper history or language-specific rules are needed. See the C language reference on functions for details: and general context on subroutines: Subroutine.

Recommended Answers

All 3 Replies

Google is your friend.

There is no such term 'procedure' in C language, only function. In some languages such as visual basic there are procedures and functions and the difference is that functions return values and procedures don't.

thanks guys...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.