Initial commit
This commit is contained in:
BIN
ForNextDay/Lec6/Lec6 - Pointers and Arrays.pdf
Normal file
BIN
ForNextDay/Lec6/Lec6 - Pointers and Arrays.pdf
Normal file
Binary file not shown.
BIN
ForNextDay/Lec6/Lec6 - forNextDay().pdf
Normal file
BIN
ForNextDay/Lec6/Lec6 - forNextDay().pdf
Normal file
Binary file not shown.
BIN
ForNextDay/Lec6/Lec6src.zip
Normal file
BIN
ForNextDay/Lec6/Lec6src.zip
Normal file
Binary file not shown.
29
ForNextDay/Lec6/Lec6src/array1.c
Normal file
29
ForNextDay/Lec6/Lec6src/array1.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define N 5
|
||||
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int iErr;
|
||||
int a[5];
|
||||
|
||||
printf("i: %p\n",&i);
|
||||
printf("j: %p\n",&j);
|
||||
printf("iErr: %p\n",&iErr);
|
||||
printf("a: %p\n",a);
|
||||
|
||||
printf("enter some integers,followed by ^D on blank line: ");
|
||||
i = 0;
|
||||
iErr = 1;
|
||||
while( iErr != 0 && i < N ){
|
||||
iErr = scanf("%d",&a[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
for(j = 0; j < i+2; j++)
|
||||
printf("a[%d]: %d @ %p\n", j, a[j], &a[j]);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
58
ForNextDay/Lec6/Lec6src/bigInt.c
Normal file
58
ForNextDay/Lec6/Lec6src/bigInt.c
Normal file
@ -0,0 +1,58 @@
|
||||
/* bigInt.c
|
||||
*
|
||||
* Demonstrates use of passing an array to a function.
|
||||
*
|
||||
* Also shows why sizeof() is not a reliable way to discover array size. It
|
||||
* *only* works correctly inside the function it's declared in. When passed
|
||||
* to a function, the *address* of teh begining of the array is passed and so
|
||||
* sizeof() returns the sizeof an address. Here's the compiler output
|
||||
* (I ignored the compile warnings to run it)
|
||||
*
|
||||
* wightman% gcc bigInt.c
|
||||
* bigInt.c:32:49: warning: sizeof on array function parameter will return size of
|
||||
* 'int *' instead of 'int []' [-Wsizeof-array-argument]
|
||||
* printf("bigInt: sizeof(a): %lu bytes\n", sizeof(arr));
|
||||
* ^
|
||||
* bigInt.c:29:16: note: declared here
|
||||
* int bigInt(int arr[], int iNarr){
|
||||
* ^
|
||||
* 1 warning generated.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define N 5
|
||||
|
||||
int bigInt(int arr[], int iNarr);
|
||||
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
int iErr;
|
||||
int a[5];
|
||||
|
||||
// sizeof() return a long unsigned int (%lu)
|
||||
printf("main: sizeof(a): %lu bytes\n", sizeof(a));
|
||||
|
||||
printf("enter some integers,followed by ^D on blank line: ");
|
||||
i = 0;
|
||||
iErr = 1;
|
||||
while( iErr != 0 && i < N ){
|
||||
iErr = scanf("%d",&a[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
printf("Biggest value: %d\n", bigInt(a,N));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int bigInt(int arr[], int iNarr){
|
||||
int i;
|
||||
int big = arr[0];
|
||||
printf("bigInt: sizeof(a): %lu bytes\n", sizeof(arr));
|
||||
for(i=1; i<iNarr; i++){
|
||||
if(arr[i] > big)
|
||||
big = arr[i];
|
||||
}
|
||||
return big;
|
||||
}
|
24
ForNextDay/Lec6/Lec6src/decompose.c
Normal file
24
ForNextDay/Lec6/Lec6src/decompose.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* decompose.c
|
||||
*
|
||||
* Demonstrates use of passing and using pointers to/in a function.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void decompose(double x, long* int_part, double* frac_part);
|
||||
int main()
|
||||
{
|
||||
long i;
|
||||
double d;
|
||||
double pie = 3.14159f;
|
||||
decompose(pie, &i, &d);
|
||||
|
||||
printf("Decomposed values for %lf: %ld, %lf\n", pie, i, d);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void decompose(double x, long* int_part, double*frac_part){
|
||||
*int_part = (long) x;
|
||||
*frac_part = x - *int_part;
|
||||
}
|
BIN
ForNextDay/Lec6/Shoebottom_Isaac_fND_6.docx
Normal file
BIN
ForNextDay/Lec6/Shoebottom_Isaac_fND_6.docx
Normal file
Binary file not shown.
Reference in New Issue
Block a user