Lecture 18: The Elegant, Abstract World of Computing

Slides:



Advertisements
Similar presentations
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Pointers Pointer Arithmetic Dale Roberts, Lecturer Computer.
Advertisements

BBS514 Structured Programming (Yapısal Programlama)1 Pointers.
1 Pointers Lecture Introduction Pointers  Powerful, but difficult to master  Simulate pass-by-reference  Close relationship with arrays and.
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
Kernighan/Ritchie: Kelley/Pohl:
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 7 - Pointers Outline 7.1Introduction 7.2Pointer.
Topic 2 Pointers CSE1303 Part A, Summer Semester,2002 Data Structures and Algorithms.
Lesson 6 - Pointers Outline Introduction Pointer Variable Declarations and Initialization Pointer Operators Calling Functions by Reference Using the const.
Pointers Pointer - A pointer is a derived data type; that is it is a data type built from one of the standard types. Its value is any of the addresses.
Pointers. Topics Pointers Pointer Arithmetic Pointers and Arrays.
CS1061 C Programming Lecture 13: Pointers A. O’Riordan, 2004.
Pointers 1 Pointers Pointers  In chapter three we looked at passing parameters to functions using call by value, and using call by reference, using reference.
Lecture 7 C Pointers Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
Computer Skills2 for Scientific Colleges 1 Pointers in C++ Topics to cover: Overview of Pointers Pointer Declaration Pointer Assignment Pointer Arithmetic.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
 2007 Pearson Education, Inc. All rights reserved C Pointers.
[S. Uludag] CIS / CSC 175 Problem Solving and Programming I Winter 2010 Suleyman Uludag Department of Computer Science, Engineering and Physics (CSEP)
Lecture 22: Reviews for Exam 2. Functions Arrays Pointers Strings C Files.
Pointers. Pointer Variable Declarations and Initialization Pointer variables – Contain memory addresses as their values – Normal variables contain a specific.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 7 - Pointers Outline 7.1Introduction 7.2Pointer.
Lecture 17: The Last Puzzle Piece with Functions.
1 Lecture 12 Pointers and Strings Section 5.4, ,
1 Object-Oriented Programming Using C++ A tutorial for pointers.
1 Lecture 8 Pointers and Strings: Part 2 Section 5.4, ,
1. Pointers –Powerful, but difficult to master –Simulate pass-by-reference –Close relationship with arrays and strings 2.
 2003 Prentice Hall, Inc. All rights reserved. 1 Lecture 5: Pointer Outline Chapter 5 Pointer continue Call by reference Pointer arithmatic Debugging.
Pointers in C by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
Chapter 7 Pointers Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
EC-111 Algorithms & Computing Lecture #9 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 9.
Lecture 9 - Pointers 1. Outline Introduction Pointer Variable Definitions and Initialization Pointer Operators Calling Functions by Reference Pointer.
Pointers Pointers are variables that contain memory addresses as their values. A variable directly contains a specific value. A pointer contains an address.
Chapter 8 Arrays, Strings and Pointers
Computer Science 210 Computer Organization
Computer Skills2 for Scientific Colleges
Week 9 - Pointers.
Functions and Pointers
Chapter 7 - Pointers Outline 7.1 Introduction
POINTERS.
EPSII 59:006 Spring 2004.
Chapter 7 - Pointers Outline 7.1 Introduction
Chapter 7 - Pointers Outline 7.1 Introduction
CSC113: Computer Programming (Theory = 03, Lab = 01)
INC 161 , CPE 100 Computer Programming
CSC113: Computer Programming (Theory = 03, Lab = 01)
ECE Application Programming
Pointers.
Functions and Pointers
Computer Science 210 Computer Organization
Pointers.
Pointers  Week 10.
Pointers and Pointer-Based Strings
Lecture 18 Arrays and Pointer Arithmetic
Pointers Call-by-Reference CSCI 230
Computer Skills2 for Scientific Colleges
Pointers Kingdom of Saudi Arabia
prepared by Senem Kumova Metin modified by İlker Korkmaz
Pointers.
7 C Pointers.
Pointers Pointers are variables that contain memory addresses as their values. A variable name refers to a specific value. A pointer contains an address.
EENG212 ALGORITHMS & DATA STRUCTURES
POINTERS.
C++ Programming Lecture 18 Pointers – Part II
Programming in C Pointers and Arrays.
Lecture 14: Problems with Lots of Similar Data
CISC181 Introduction to Computer Science Dr
Programming fundamentals 2 Chapter 3:Pointer
Presentation transcript:

Lecture 18: The Elegant, Abstract World of Computing

Arrays and Pointers Arrays and pointers closely related Array name like a constant pointer Arrays passed to a function by reference Pointers can do array subscripting operations

Relationship between Pointers and Arrays Define an array b[5] and a pointer bPtr int b[5]; int *bPtr; To set them equal to one another use bPtr = b; The array name (b) is actually the address of first element of the array. bPtr = &b[ 0 ]; Explicitly assigns the address of first element of b to bPtr. Element b[ 3 ] Can be accessed by *(bPtr + 3) --- pointer/offset notation where 3 is called the offset. Can be accessed by bPtr[ 3 ] --- pointer/subscript notation bPtr[ 3 ] same as b[ 3 ] Can also be accessed by *(b+3) --- view b as a constant pointer *b accesses to b[0]

Relationship between Pointers and Arrays What is the difference? int b[5], a[5]; int *objPtr; A pointer can be assigned to point to different objects. objPtr = b; objPtr = a; Array name likes a constant pointer. a = objPtr; b = a; Pointers Dereferencing a NULL pointer is NOT allowed. int *aPtr = NULL, *bPtr = 0; int x; x = *aPtr; x = * bPtr; Dereferencing a pointer not pointing to an object is NOT allowed. int *aPtr , x;

Passing Arrays by Reference Array name like a constant pointer RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int *sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, &total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int *sum ) int k; *sum = 0; for (k = 0; k < size; k++) { *sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 … … In main(), just before call into sumRef()

Passing Arrays by Reference Array name like a constant pointer RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int *sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, &total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int *sum ) int k; *sum = 0; for (k = 0; k < size; k++) { *sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 0xBFFFF840 k 0xBFFFF85C … In main(), while calling into sumRef()

Passing Arrays by Reference Array name like a constant pointer RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int *sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, &total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int *sum ) int k; *sum = 0; for (k = 0; k < size; k++) { *sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 0xBFFFF840 k 0xBFFFF85C … In sumRef(), just after execute “*sum = 0;”

Passing Arrays by Reference Array name like a constant pointer RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int *sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, &total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int *sum ) int k; *sum = 0; for (k = 0; k < size; k++) { *sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 0xBFFFF840 k 0xBFFFF85C … In sumRef(), …

Passing Arrays by Reference Array name like a constant pointer RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int *sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, &total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int *sum ) int k; *sum = 0; for (k = 0; k < size; k++) { *sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 1 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 0xBFFFF840 k 0xBFFFF85C … In sumRef(), after execute “*sum += x[k];”

Passing Arrays by Reference Array name like a constant pointer RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int *sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, &total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int *sum ) int k; *sum = 0; for (k = 0; k < size; k++) { *sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 1 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 0xBFFFF840 k 0xBFFFF85C 1 … In sumRef(), increment k

Passing Arrays by Reference Array name like a constant pointer RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int *sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, &total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int *sum ) int k; *sum = 0; for (k = 0; k < size; k++) { *sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 3 1 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 0xBFFFF840 k 0xBFFFF85C 1 1 … In sumRef(), perform addition

Passing Arrays by Reference Array name like a constant pointer RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int *sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, &total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int *sum ) int k; *sum = 0; for (k = 0; k < size; k++) { *sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 3 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 0xBFFFF840 k 0xBFFFF85C 2 1 … In sumRef(), increment k

Passing Arrays by Reference Array name like a constant pointer RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int *sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, &total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int *sum ) int k; *sum = 0; for (k = 0; k < size; k++) { *sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 6 3 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 0xBFFFF840 k 0xBFFFF85C 2 … In sumRef(), perform addition

Passing Arrays by Reference Array name like a constant pointer RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int *sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, &total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int *sum ) int k; *sum = 0; for (k = 0; k < size; k++) { *sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 15 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 0xBFFFF840 k 0xBFFFF85C 5 … In sumRef(), right after the for loop

Passing Arrays by Reference Array name like a constant pointer RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int *sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, &total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int *sum ) int k; *sum = 0; for (k = 0; k < size; k++) { *sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 15 … … In main(), right after call sumRef()

Call-by-Value via Call-by-Reference Passing array by reference Passing integer/char/float by value RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int sum ) int k; sum = 0; for (k = 0; k < size; k++) { sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 … … In main(), just before call into sumRef()

Call-by-Value via Call-by-Reference Passing array by reference Passing integer/char/float by value RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int sum ) int k; sum = 0; for (k = 0; k < size; k++) { sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 k 0xBFFFF85C … In main(), while calling into sumRef()

Call-by-Value via Call-by-Reference Passing array by reference Passing integer/char/float by value RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int sum ) int k; sum = 0; for (k = 0; k < size; k++) { sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 k 0xBFFFF85C … In sumRef(), just after execute “sum = 0;”

Call-by-Value via Call-by-Reference Passing array by reference Passing integer/char/float by value RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int sum ) int k; sum = 0; for (k = 0; k < size; k++) { sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 k 0xBFFFF85C … In sumRef(), …

Call-by-Value via Call-by-Reference Passing array by reference Passing integer/char/float by value RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int sum ) int k; sum = 0; for (k = 0; k < size; k++) { sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 1 k 0xBFFFF85C … In sumRef(), after execute “sum += x[k];”

Call-by-Value via Call-by-Reference Passing array by reference Passing integer/char/float by value RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int sum ) int k; sum = 0; for (k = 0; k < size; k++) { sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 1 k 0xBFFFF85C 1 … In sumRef(), increment k

Call-by-Value via Call-by-Reference Passing array by reference Passing integer/char/float by value RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int sum ) int k; sum = 0; for (k = 0; k < size; k++) { sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 1 3 k 0xBFFFF85C 1 … In sumRef(), perform addition

Call-by-Value via Call-by-Reference Passing array by reference Passing integer/char/float by value RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int sum ) int k; sum = 0; for (k = 0; k < size; k++) { sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 … x 0xBFFFF850 0xBFFFF82C size 0xBFFFF854 5 sum 0xBFFFF858 15 k 0xBFFFF85C 5 … In sumRef(), right after the for loop

Call-by-Value via Call-by-Reference Passing array by reference Passing integer/char/float by value RAM … #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, total ); printf(“%d\n”, total); return 0; } void sumRef( int *x, int size, int sum ) int k; sum = 0; for (k = 0; k < size; k++) { sum += x[k]; return; a[0] 0xBFFFF82C 1 a[1] 0xBFFFF830 2 a[2] 0xBFFFF834 3 a[3] 0xBFFFF838 4 a[4] 0xBFFFF83C 5 total 0xBFFFF840 … … In main(), right after call sumRef()

In-class Programming Assignment 7.034 0.361 2.550 11.588 19.166 18.317 9.821 1.490 0.983 8.766 17.684 19.537 12.622 3.296 0.134 6.043 15.590 19.998 15.214 5.636 0.071 3.634 13.050 j #include <stdio.h> #define SIZE 3000 #define WINDOW 10 void readin(double sonar[SIZE]); void denoising(double *sonarPtr, double *rPtr); int main (){ double sonar[SIZE]; double denoisedSonar[SIZE]; readin(sonar); denoising(sonar, denoisedSonar); return 0; } void denoising(double *sonarPtr, double *rPtr) { /* You need to finish this function */ For every possible starting index j of the sliding window, sum = 0; compute the total sum of the sonar data inside the sliding window; rPtr[j] = sum / WINDOW; void readin(double sonar[SIZE]){

Practice Question Q. What is the output of the following program? #include<stdio.h> #define SIZE 5 void sumRef( int *x, int size, int sum ); int main( void ) { int a[SIZE] = {1, 2, 3, 4, 5}; int total = 0; sumRef( a, SIZE, total ); printf(“%d %d\n”, *a, total); return 0; } void sumRef( int *x, int size, int sum ) int k; sum = 0; for (k = 0; k < size; k++) { sum += x[k]; x[k] *= 3; 3 15 1 15 3 0 1 0 Solution: C

Practice Question Q. To assign the third element b[2] of an array b to the variable x, which of the following is WRONG? int x, b[5] = {1, 2, 3, 4, 5}; int *bPtr; bPtr = b; x = *(bPtr+2); x = bPtr[2]; x = *(b+2); b = b + 2; x = *b; bPtr += 2; x = *bPtr; Solution: D