Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress #14

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Binary file added a.out
Binary file not shown.
43 changes: 43 additions & 0 deletions first-c.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Every C program is an operating system process/executable
// C uses the same kind of comments as JavaScript

// #includes allow us to combine different files into a single program
// #including can be pointed at a file that you wrote, or it can be
// pointed at a file someone else wrote. You have to know where the
// file is, and whether or not it is the one you need!
#include <stdio.h>
/*Lines 10 - 18 are an example of various C primitives
int integerFunction(int input) {
return 0;
}
float floatFunction(float input) {
return 0.0;
}
float mixedFunction(float input) {
return 0.0;
}
*/

int main(int argc, char** argv) {
/* char** means one of two things:
(1) someone is doing something complicated
aka an algorithm with this object (it is a pointer to a pointer)
(2) or it means it is a two-dimensional array >> argv[][]

argv = [['g', 'c', 'c'], ['a', 'b', 'c'], ['g', 'c', 'c'],['h', 'i']];

NOTE: In C, a string is an array of characters.
(1) a string is in double quotes
(2) a character (char) is in single quotes
*/

// vvv the simplest possible C program
return 100;

// printf("argc is: ");
// printf("%d\n", argc);

// for(int i = 0; i < argc; ++i) {
// printf("%s\n", argv[i]);
// }
}
113 changes: 106 additions & 7 deletions first_C_programming_assignment.C
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* primitives (int char float double)
* loops, break, continue
* branches if else else if, while
* arrays
* primitives (int char float double)
* loops, break, continue
* branches if else else if, while
* arrays
* structs (to become classes)
* ^^^ ^^^ ^^^ ^^^ ^^^
* Operating Systems C Lesson Assignment 1
Expand Down Expand Up @@ -37,12 +37,111 @@
// In order to run a program, you must:
// Write this C file
// Make it syntactically correct
// Compile the program with gcc my_first_C_program.C -o my_output
// Compile the program with gcc first_C_programming_assignment.C -o my_output
// ./my_output

// READ ABOUT: vvv Popular Header Files
#include <stdio.h>

int main(int argc, char** argv) {
printf("Hello world!");
// (1) * primitives (int char float double)
int integerAddFunction()
{
int a = 3;
float b = 4.5;
double c = 5.25;
float sum;

sum = a + b + c;
// printf stands for 'print formatted'
printf("The sum of a, b, and c is float %f. \n", sum);
printf("\n");
return 0;
}
// (2) * loops, break, continue

int forLoopFunction()
{
printf("Start of forLoop Function: \n");
int A[] = {2, 4, 6, 8};
int i;

for (i = 0; i < 4; i++)
{
printf("Address = %d\n", &A[i]);
printf("Address = %d\n", A + i);
printf("Pointer Value = %d\n", A[i]);
printf("Pointer Value = %d\n", *(A + i));
printf("\n");
}
printf("Total Array Size in Bytes = %d\n", sizeof(A));
printf("\n");
return 0;
}

int whileLoopFunction()
{
printf("Start of WhileLoop Function: \n");
char A[7] = "Steven";
int i = 0;

while(A[i] != '\0')
{
printf("%c", A[i]);
printf("\n");
i++;
}
printf("\n");
return 0;
}

// (3) * branches if else else if, while

// (4) * arrays
int printArray()
{
printf("Start of PrintArray Function: \n");

int A[] = {2, 4, 6, 8};
printf("Memory Address = %d\n", A);
printf("Memory Address = %d\n", &A[0]);
printf("Pointer Value = %d\n", A[0]);
printf("Pointer Value = %d\n", *A);
printf("\n");

/* defines an array of 6 integers */
int numbers[6];
/* populates the array */
numbers[0] = 0;
numbers[1] = 1;
numbers[2] = 2;
numbers[3] = 3;
numbers[4] = 4;
numbers[5] = 5;
/* print the 3rd number from the array */
return printf("The 3rd number in the array is: %d. \n", numbers[3]);

char name[] = "Stevie Magic";


}

// (5) * structs (to become classes)


// the main() f(x) invokes other functions within it
// it is the first f(x) to be called when program starts execution
// the diff btwn int main() VS. void main() is the return type
// (i.e., VOID will not return a value to the OS
int main(int argc, char** argv) {
// READ ABOUT: Program Status Variable Integer
integerAddFunction();

forLoopFunction();

whileLoopFunction();

printArray();

printf("Hello world!\n");
return 0;
}
Binary file added my_output
Binary file not shown.