суббота, 5 июня 2010 г.
Function pointers
Assume there are some functions
int func(int a, double b);
int fonc(int a, double b);
To create a pointer to these functions:
int(*p)(int, double);
p = func;
(*p)(1, 1.22);
/* or */
p = fonc;
p(2, 3.44) ;
Note: All functions that are used with the same function pointer must have the same parameters and return type.
Assume there are some functions
int func(int a, double b);
int fonc(int a, double b);
To create a pointer to these functions:
int(*p)(int, double);
p = func;
(*p)(1, 1.22);
/* or */
p = fonc;
p(2, 3.44) ;
Note: All functions that are used with the same function pointer must have the same parameters and return type.
воскресенье, 30 мая 2010 г.
Week 3 in OOP344
Lazy evaluation
Assume we have an array with 10 elements
and we want to print only those are greater than 3
so
int arr[10] = {1,2,3,4,5,2,7,2,5,9};
for(int i = 0; i < 10; i++){
arr[i]>3 && printf("%d \n", a[i]); /* the second part of the condition is evaluated only when the first one is true */
}
Assume we have an array with 10 elements
and we want to print only those are greater than 3
so
int arr[10] = {1,2,3,4,5,2,7,2,5,9};
for(int i = 0; i < 10; i++){
arr[i]>3 && printf("%d \n", a[i]); /* the second part of the condition is evaluated only when the first one is true */
}
понедельник, 17 мая 2010 г.
Подписаться на:
Сообщения (Atom)