Part 1 Landscape Hannu Laine. Pointer parameters //prototype of swap void swap(int *a, int *b); //application void main(void) { in number1 = 1, number2.

Slides:



Advertisements
Similar presentations
#include void main() { float x = 1.66, y = 1.75; printf(%f%f,ceil(x), floor(y)); }
Advertisements

C++ crash course Class 10 practice problems. Pointers The following function is trying to swap the contents of two variables. Why isnt it working? void.
1 Pointers and Strings Section 5.4, , Lecture 12.
For(int i = 1; i
EC-111 Algorithms & Computing Lecture #10 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Spring Semester 2013 Lecture 5
Lectures 10 & 11.
Pointers Pointer is a variable that contains the address of a variable Here P is sahd to point to the variable C C 7 34……
Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
void count_down (int count) { for(i=count; i>1; i--) printf(" %d\t", count); } printf("A%d\n", count); if(count>1) count_down(count-1); printf("B%d\n",
Functions Prototypes, parameter passing, return values, activation frams.
1 Chapter Thirteen Pointers. 2 Pointers A pointer is a sign used to point out the direction.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
Structures Spring 2013Programming and Data Structure1.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
Week 8 Arrays Part 2 String & Pointer
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
C Pointers Systems Programming Concepts. PointersPointers  Pointers and Addresses  Pointers  Using Pointers in Call by Reference  Swap – A Pointer.
C Pointers Systems Programming. Systems Programming: Pointers 2 Systems Programming: 2 PointersPointers  Pointers and Addresses  Pointers  Using Pointers.
Introduction to C Programming CE
Parameter Passing to Functions in C. C Parameter passing Review of by-value/by-reference.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 9: Pass-by-Value.
Презентація за розділом “Гумористичні твори”
Центр атестації педагогічних працівників 2014
Галактики і квазари.
Характеристика ІНДІЇ.
Процюк Н.В. вчитель початкових класів Боярської ЗОШ І – ІІІ ст №4
1 Arrays & functions Each element of an array acts just like an ordinary variable: Like any ordinary variable, you can pass a single array element to a.
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);
Built into qsort is a function that can swap two given array elements.
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
Духовні символи Голосіївського району
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 12P. 1Winter Quarter User-Written Functions Lecture 12.
Functions & Pointers in C Jordan Erenrich
/* example program to demonstrate the passing of an array */ #include int maximum( int [] ); /* ANSI function prototype */ int maximum(
Cop3530sp12. Parameter passing call by value- appropriate for small objects that should not be altered by the function call by constant reference- appropriate.
CSCI 62 Data Structures Dr. Joshua Stough December 2, 2008.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Arrays. Example Write a program to keep track of all students’ scores on quiz 1. Need a list of everyone’s score Declare 14 double variables? What about.
Array Sort. Sort Pass 1 Sort Pass 2 Sort Pass 3.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Pointers Call-by-Reference.
C Language By Sra Sontisirikit
Chapter 5 Functions DDC 2133 Programming II.
Alternate Version of STARTING OUT WITH C++ 4th Edition
Shaker.
Pointers Call-by-Reference CSCI 230
Проф. д-р Васил Цанов, Институт за икономически изследвания при БАН
ЗУТ ПРОЕКТ на Закон за изменение и допълнение на ЗУТ
О Б Щ И Н А С И Л И С Т Р А П р о е к т Б ю д ж е т г.
Електронни услуги на НАП
Боряна Георгиева – директор на
РАЙОНЕН СЪД - БУРГАС РАБОТНА СРЕЩА СЪС СЪДЕБНИТЕ ЗАСЕДАТЕЛИ ПРИ РАЙОНЕН СЪД – БУРГАС 21 ОКТОМВРИ 2016 г.
Сътрудничество между полицията и другите специалисти в България
Съобщение Ръководството на НУ “Христо Ботев“ – гр. Елин Пелин
НАЦИОНАЛНА АГЕНЦИЯ ЗА ПРИХОДИТЕ
ДОБРОВОЛЕН РЕЗЕРВ НА ВЪОРЪЖЕНИТЕ СИЛИ НА РЕПУБЛИКА БЪЛГАРИЯ
Съвременни софтуерни решения
ПО ПЧЕЛАРСТВО ЗА ТРИГОДИШНИЯ
от проучване на общественото мнение,
Васил Големански Ноември, 2006
Програма за развитие на селските райони
ОПЕРАТИВНА ПРОГРАМА “АДМИНИСТРАТИВЕН КАПАЦИТЕТ”
БАЛИСТИКА НА ТЯЛО ПРИ СВОБОДНО ПАДАНЕ В ЗЕМНАТА АТМОСФЕРА
МЕДИЦИНСКИ УНИВЕРСИТЕТ – ПЛЕВЕН
Стратегия за развитие на клъстера 2015
Моето наследствено призвание
Правна кантора “Джингов, Гугински, Кючуков & Величков”
Безопасност на движението
Simulating Reference Parameters in C
Presentation transcript:

Part 1 Landscape Hannu Laine

Pointer parameters //prototype of swap void swap(int *a, int *b); //application void main(void) { in number1 = 1, number2 = 2; swap(&number1, &number2); printf("%d %d", number1, number2); } //implementation of swap void swap(int *a, int *b) { int aux; aux = *a; *a = *b; *b = aux; } Reference parameters Comparing pointer parameters and reference parameters Back //prototype of swap void swap(int &a, int &b); //application void main(void) { in number1 = 1, number2 = 2; swap(number1, number2); //pointers are // passed instead of values printf("%d %d", number1, number2); } //implementation of swap void swap(int &a, int &b) { int aux; aux = a;//deferencing is used internally a = b;//with a and b b = aux; }

Returning a pointer //prototype of a function int *getMax(int *arr, int n); //application int main(void) { int maxValue; int array[6] = {3, 5, 2, 8, 6, 7}; printf (”%d”, *getMax(array, 6)); //Right value maxValue = *getMax(array, 6); *getMax (array, 6) = *getMax (array, 6) *10; //Left value } //implementation getMax int *getMax(int *arr, int n) { int i, maxi = 0; for (i = 1 ; i < n ; i++) if (arr [ i ] > arr [ maxi ] ) maxi = i; return &arr[maxi]; } Returning a reference Returning a pointer and returning a reference Back //prototype of a function int &getMax(int *arr, int n); //application int main(void) { int maxValue; int array[6] = {3, 5, 2, 8, 6, 7}; printf (”%d”, getMax(array, 6)); //Right value maxValue = getMax(array, 6); getMax(array, 6) = getMax(array, 6) *10; //Left value } //implementation getMax int &getMax(int *arr, int n) { int i, maxi = 0; for (i = 1 ; i < n ; i++) if (arr [ i ] > arr [ maxi ] ) maxi = i; return arr[maxi]; }