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

BIN
ForNextDay/Lec5/Lec5src.zip Normal file

Binary file not shown.

View File

@ -0,0 +1,25 @@
// pointing.c
/*
* Never dereference an unitialized pointer!
*
* Assigning a value to an unitialized pointer much worse!
*/
#include <stdio.h>
#include <stdlib.h>
#define DEBUG 0
int main(int argc, char * * argv)
{
int a = 5;
int b = 17;
int* pa;
int* pb;
// what happens if you leave these two statements out? Why?
pa = &a;
pb = &b;
#if DEBUG > 0
printf("main: a = %d, b = %d, argc = %d\n", *pa, *pb, argc);
#endif
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,18 @@
// forscope.c
/*
* - Should this compile? Why/why not?
* - What will the output be?
* - Explain the output.
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
int i = 0;
for(int i=0;i<5;i++){
printf("%d\n",i);
}
printf("%d\n",i);
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,28 @@
// ifscope.c
/*
* Should this compile? Why/why not?
* What will the output be if:
* (i) i=1, j=2
* (i) i=2, j=1
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
int iErr;
int i;
int j;
printf("Enter two integers: ");
iErr = scanf("%d %d", &i, &j);
if(iErr != 2)
{
fprintf(stderr,"Egads - something went wrong!\n");
return EXIT_FAILURE;
}
if(i>j){
int i = 0;
printf("%d\n",i);
}
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,20 @@
// pointing.c
/*
* Never dereference an unitialized pointer!
*
* Assigning a value to an unitialized pointer much worse!
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * * argv)
{
int a = 5;
int b = 17;
int* pa;
int* pb;
// what happens if you leave these two statements out? Why?
pa = &a;
pb = &b;
printf("main: a = %d, b = %d, argc = %d\n", *pa, *pb, argc);
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,21 @@
// swap.c
/*
*/
#include <stdio.h>
#include <stdlib.h>
void swap(int i, int j);
int main(int argc, char* argv[]) {
int i = 10;
int j = 99;
printf("i = %d; j = %d\n", i, j);
swap(i,j);
printf("i = %d; j = %d\n", i, j);
return EXIT_SUCCESS;
}
void swap(int i, int j) {
int swap;
swap = i;
i = j;
j = swap;
}