Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Pointers Review - Lecture Slides | CSE A205, Study notes of Engineering

Material Type: Notes; Class: Introduction to C Programming for Engineers; Subject: Computer Systems Engineering ; University: University of Alaska - Anchorage; Term: Fall 2008;

Typology: Study notes

2009/2010

Uploaded on 03/28/2010

koofers-user-8s2
koofers-user-8s2 🇺🇸

9 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE294A
Introduction to C Programming for Engineers
Lecture #15
Jeffrey Miller, Ph.D.
pf3
pf4
pf5
pf8

Partial preview of the text

Download Pointers Review - Lecture Slides | CSE A205 and more Study notes Engineering in PDF only on Docsity!

CSE294A

Introduction to C Programming for Engineers

Lecture

Jeffrey Miller, Ph.D.

Pointers Review

Pointers are variables whose values are memoryaddresses

int *count_ptr; int count = 10; count_ptr = &count; printf (“%d”, count); printf (“%d”, *count_ptr); printf (“%d”, count_ptr); printf (“%d”, &count); printf (“%d”, &count_ptr);

Function Pointers

Assume that func1 is going to take a function as aparameter, which will be either func2 or func

First, we declare the function prototypes just as wehave done before, with one difference for func

void func1(float, int (*)(int, float)); int func2 (int, float); int func3 (int, float);

Function Pointers

Then when we call func1, we have to pass a floatand a pointer to a function that returns an int andtakes an int and a float as parameters

float num = 3.0f; func1(num, func2); func1(num, func3);

Program

Write a program that uses bubble sort to sort an array ofvalues. The array to sort can be hard-coded, but whetherto sort the list in ascending or descending order will bedecided by prompting the user. Instead of having twodifferent bubble sort functions, have one bubble sortfunction that takes another function as a parameter. Thatfunction will be used to compare for sorting in ascendingor descending order. Output the sorted array. Here is thebubble_sort function prototype (array, size, comparefunction): void bubble_sort(int , int, int ()(int, int));

Homework

Homework #7 will be posted soon!