0% found this document useful (0 votes)
72 views

CM304

This document discusses passing array elements and arrays as arguments to functions in C programming. It begins with objectives and a recap of array initialization. It then explains that array elements and entire arrays can be passed to functions, similarly to passing variables. Examples are provided to demonstrate passing array elements and entire arrays as arguments. The key points are that array elements are passed by value while entire arrays are passed by reference, with the function receiving access to the actual array. A quiz and frequently asked questions section conclude the document.

Uploaded by

api-3849444
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

CM304

This document discusses passing array elements and arrays as arguments to functions in C programming. It begins with objectives and a recap of array initialization. It then explains that array elements and entire arrays can be passed to functions, similarly to passing variables. Examples are provided to demonstrate passing array elements and entire arrays as arguments. The key points are that array elements are passed by value while entire arrays are passed by reference, with the function receiving access to the actual array. A quiz and frequently asked questions section conclude the document.

Uploaded by

api-3849444
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 18

DEPARTMENT OF TECHNICAL EDUCATION

ANDHRA PRADESH
Name of the faculty : P. Alimullah khan .
Designation : Lecturer.
Branch : Computer Engineering.
Institute : V.K.R & V.N.B Polytechnic Gudivada.
Year/Semester : III Semester.
Subject : UNIX & C.
Subject Code : CM-304.
Topic : Understand basics of Arrays.
Duration : 50 Min
Sub Topic : Passing array elements as arguments.
Teaching Aids : Diagram and animations.
CM304.60 1
Objective

On completion of this period, you would be


able to know..

 Passing array as arguments to functions.

CM304.60 2
Recap

In the previous class, we have discussed about

 Initialization of an array.

CM304.60 3
Passing Arrays as argument to functions

We can pass

 An array element as argument to a function.

 An entire array as argument to a function.

CM304.60 4
Passing array elements as arguments

 An array elements can be passed as arguments


to other functions.
 Similar to passing variable to a function.
Example:
int a[5] is an array and cub( ) is a function
to calculate the cube of the giving number.
array elements can be passed to cub( ).

CM304.60 5
Simple program using passing arrays
elements as arguments
#include<stdio.h>
int tol(int)
main()
{
int i, a[5];
printf (“enter the elements”);
for (i=0;i<5;i++)
scanf (“%d”, &a[i]);
printf (“the array elements”);

CM304.60 6
Simple program using passing arrays
elements as arguments Contd..
for (i=0;i<5;i++)
printf (“%d”, a[i]);
functio for (i=0;i<5;i++)
n printf (“%d”, tol(a[i]));
}
int tol( int m1);
{ Argume
int m2; nt
m2=m1+m1+m1;
return(m2);
}
CM304.60 7
Passing an arrays elements to functions

main ( ) tol

m1

a[i]

m2

Fig 60.1
CM304.60 8
Passing an arrays elements to functions

Entire array can be passed to a function as


argument:

 The called function receives access to the actual


array, rather than a copy of the values in the
array.

CM304.60 9
Passing an arrays elements to functions
#include < stdio.h>
main( )
{
int grade[50];
.
first (grade);
.
}
int first( int f_ grade[])
{
.
.} CM304.60 10
Passing an arrays elements to functions

 In the above program array grade elements want

be passed to subprograms. Instead f_

grade will also get the access to grade.

 A two dimensional array can be passed as

arguments to a function .

CM304.60 11
Passing an arrays elements to functions

main ( ) int first (int f_ grade)


{ {
int grade [50]; .
. }
first (grade);
}

CM304.60 12
Summary

In this class, we have discussed about

 How to pass arrays as argument to a function.

CM304.60 13
Quiz

1. How to pass the elements in an array?

a) passing the functions.

b) passing as arguments to other fun().

c) none.

CM304.60 14
Quiz

1. How to pass the elements in an array?

a) passing the functions.

b) passing as arguments to other fun().

c) none.

CM304.60 15
Quiz

2. When you pass an array as an argument to a

function ,what actually gets passed?

a) address of the array.

b) value of the elements of the array

c) address of the first element of the array.

CM304.60 16
Quiz

2. When you pass an array as an argument to a

function ,what actually gets passed?

a) address of the array.

b) value of the elements of the array.

c) address of the first element of the array.

CM304.60 17
Frequently Asked Questions

1. Explain how array elements can be passed to


a function.

2. Explain how an array can be passed to a


function.

3. Write a ‘C’ program to illustrate the concept of


passing arrays as argument to a function.
CM304.60 18

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy