Purchase Solution

Write a C program to call a function by passing a pointer reference to an array of integers

Not what you're looking for?

Ask Custom Question

If you choose to answer problem 1 in Section B, you must complete both parts a and b.

a) Write a C program that has a declaration in main() to store the following numbers into an array named channels: 2, 4, 5, 7, 9, 11, 13. There should be a function call to display() that accepts the channels as an argument named channels and then displays the numbers using the pointer notation *(channels + i).

b) Modify this display() function to alter the address in channels. Always use the expression *channels rather than *(channels + i) to retrieve the correct elements.

Purchase this Solution

Solution Summary

This solution illustrates how to pass the reference of an array to a function. It also teaches how to use the pointer notation in order to access the values of an array.

Solution Preview

a)
#include <stdio.h>

void display(int *p, int N); /*Function prototype*/

int main(){
int channels[] = {2, 4, 5, 7, 9, 11, 13}; /*Declaration of the channels array*/
int N = 7; /*Size of Array, needed to display the array*/

display(channels, N); /*Sending the the pointer to the array, ...

Purchase this Solution


Free BrainMass Quizzes
Basic Networking Questions

This quiz consists of some basic networking questions.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

C++ Operators

This quiz tests a student's knowledge about C++ operators.