Initial commit

This commit is contained in:
2023-05-22 23:28:51 -03:00
commit 5c1403aa91
467 changed files with 18649 additions and 0 deletions

Binary file not shown.

Binary file not shown.

BIN
ForNextDay/Lec6/Lec6src.zip Normal file

Binary file not shown.

View 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;
}

View 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;
}

View 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;
}

Binary file not shown.