A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to pass a one dimensional (1D) array to a function
Q:

C program to pass a one dimensional (1D) array to a function

0

C program to pass a one dimensional (1D) array to a function

Given a one dimensional array (an integer array) and we have to pass the array to a function and print the elements using C program.

Here is the function that we have used in the program,

void arrayfun(int*ptr , int count)

Here,

  • void is the returns type of the function i.e. this function does not return any value.
  • int *ptr is an integer pointer that will store the based address of the integer array which will be passed through the main() function.
  • int count is an integer variable that will store the total number of elements which will be passed through the main() function.

Function calling statement,

arrayfun(array,9);

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to pass a one dimensional array to function in C

/*  
C program to pass 1D array to a function
*/

#include <stdio.h>

// function to print 1D array elements
void arrayfun(int*ptr , int count)
{
    int i=0;
    
    for(i=0;i<count;i++)
    {
        printf("\nArray [%d] : %d",i,ptr[i]);  fflush(stdout);
    }
    
}

// main function
int main()
{
	// Declare a buffer of type "char"
	int array[10] = {1,2,3,4,5,6,7,8,9};
	
	// Passing 1D-array to Function
	arrayfun(array,9);
	return 0;
}

Output

Array [0] : 1
Array [1] : 2
Array [2] : 3
Array [3] : 4
Array [4] : 5
Array [5] : 6
Array [6] : 7
Array [7] : 8
Array [8] : 9

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now