Show Menu

ECE160 Test 2 Cheat Sheet by

Functions

Used to break problem down to small, bite sized pieces
Have an optional type of return value, a name and optional arguments
Functions return at most, ONE value
Functions must be prototyped or declared before usage

Extra Types

int
−2,147­,48­3,648 to +2,147­,48­3,647
unsigned int
0 to 4,294,­967,295
int64
-9,223­,37­2,0­36,­854­,77­5,808 to +9,223­,37­2,0­36,­854­,77­5,807

Call by Address

#include<stdio.h>
void interchange(int num1,int num2)
{
    int temp;
    temp = *num1;
    num1 = num2;
    *num2 = temp;
}
int main() {
    int num1=50,num2=70;
    interchange(&num1,&num2);
    printf("\nNumber 1 : %d",num1);
    printf("\nNumber 2 : %d",num2);
    return(0);
}
OUTPUT
Number 1 : 70
Number 2 : 50

Call Value

 

Switch

CBR vs CBV

Array Sample

a[0] = 4;
a[1] = 5;
a[2] = 33;
a[3] = 13;
a[4] = 1;
 

Call-B­y-Value Steps

Copy of original parameter is created & passed to the called function
Updates inside method will NOT affect the original value of the variable in the calling function
scope is limited, therefore it cannot alter values inside main function

Call by Value

#include<stdio.h>
void interchange(int number1,int number2)
{
    int temp;
    temp = number1;
    number1 = number2;
    number2 = temp;
}
int main() {
    int num1=50,num2=70;
    interchange(num1,num2);
    printf("\nNumber 1 : %d",num1);
    printf("\nNumber 2 : %d",num2);
    return(0);
}
OUTPUT
Number 1 : 50
Number 2 : 70

CallRef

Call by ref = call by address

Download the ECE160 Test 2 Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/0mghansda_ece160-test-2.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.