Takes something returns nothing functions in C

 When a function has arguments, it receive any data from the calling function but it returns no values.
Syntax :
Function declaration : void function ( int );
Function call : function( x );
Function definition:
             void function( int x )
             {
               statements;
             }

// C code for function 
// with argument but no return value
#include <stdio.h>
  
void function(int, int[], char[]);
int main()
{
    int a = 20;
    int ar[5] = { 10, 20, 30, 40, 50 };
    char str[30] = "Study for future";
    function(a, &ar[0], &str[0]);
    return 0;
}
  
void function(int a, int* ar, char* str)
{
    int i;
    printf("value of a is %d\n\n", a);
    for (i = 0; i < 5; i++) {
        printf("value of ar[%d] is %d\n", i, ar[i]);
    }
    printf("\nvalue of str is %s\n", str);
}
Output:
value of a is 20
value of ar[0] is 10
value of ar[1] is 20
value of ar[2] is 30
value of ar[3] is 40
value of ar[4] is 50
The given string is "Study for future"

No comments:

Post a Comment

Featured Post

Core and Advance Python

                      Language Fundamentals