365H615 | Skillshare Projects

--

--

# 365H615

Variables

short

• 12

int

• 454654

long

• 5959559524532

float

• 4543.543

double

• 2.65689949

char

• a
• %
• #
• e
• x
• *

pointers

• pointers point to other pieces of data by going to the address that they are stored in

int *address = 0;                  (this is called making the address null - setting it to zero)

int x = 18;                               (set variable)

address = &x;                       (this is called referencing the address)

*address = 27                      (this is called deferencing the pointer)

Structures

• structures or structs set coordinate points for objects on the screen

struct Point {

x = 25;

y = 100;

}

struct Point a;

a.x = 25;

a.y = 100;

---------------------------------------------------------------------

Functions consists of three parts

int area (int sideA, int sideB)

1. Return type

tells you which type of value you your function will return - int, float, char, double, etc

2. Name

tells you what your building and allows you to reuse the code

3. Paramteters

literally the pieces that are needed to build the functions

int main(int argc, const char * argv[])

------------------------------------------------------

int area (int sideA, int sideB)

{

int result = sideA * sideB;

return result;

}

int means that we will return a number with this method

-------------------------------------------------------

to call the function, set values or ARGUMENTS to the PARAMETERS in the function that you built

int total = area (4,2);

** in this case, when we are CALLING THE FUNCTION and not BUILDING THE FUNCTION, the  and the  are considered ARGUMENTS and not PARAMETERS because we are calling the functions, we are not BUILDING the functions. PARAMATERS would be sideA and sideB, not  and .

--------------------------------------------------------

Stack Frame

local variables - only exist within the main () function.

*/

//begin designing function

int perimeter (int side1, int side2, int side3, int side4)

{

int perimQuad = side1 + side2 + side3 + side4;

}

int main(int argc, const char * argv[])

{

//calculate perimeter of quadralateral

int PerimTrapperzoid = perimeter(12, 12, 15, 34);

printf("The perimteter of the trapazoid is: %i", PerimTrapperzoid);

}

-------------------------------------------------

#include <stdio.h>

#include "unistd.h"

void countDown (int days)

{

if (days == 0) {

printf("Get Bread MY NIGGA \n");

}

else {

int oneLessDay = days - 1;

printf("there are %i days left and tomorrow there will be %i days left \n", days, oneLessDay);

sleep (2);

countDown(oneLessDay);

}

}

int main(int argc, const char * argv[])

{

//Day Counter

int numDays = 5;

countDown(numDays);

return 0;

}

--------------------------------------------------------------

Global Variables

#include <stdio.h>

//Global variables

int total = 10;

//static variables only exists within this file's main

static  int value = 13;

void resetTotal()

{

total = 0;

}

void updateTotal()

{

total = total + 1;

}

int main(int argc, const char * argv[])

{

int total = 15;

/*

local variables take precendent over global variables, so if a global variable and a local variable

have the same name, the program reads the output value of the local variable

*/

printf("Total = %i \n", total);

resetTotal();

// call global function by typing its name

printf("Total = %i \n", total);

updateTotal();

printf("Total = %i \n", total);

return 0;

}