Overview (1A) Young Won Lim 9/25/17
|
|
- Ira Porter
- 6 years ago
- Views:
Transcription
1 Overview (1A)
2 Copyright (c) Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". Please send corrections (or suggestions) to youngwlim@hotmail.com. This document was produced by using OpenOffice.
3 Calculating the Mean The mean of 3 numbers m = a b c = = 50 Integer number fixed point number = = Real number floating point number Overview 3
4 Calculating a mean in C int a, b, c; int mean; a = 40; b = 50; c = 60; mean = (a + b +c) / 3; int a, b, c; float mean; a = 45; b = 53; c = 63; mean = (a + b +c) / 3.0; * Variable * Type * Assignment * Operator Overview 4
5 Variables int Type int a, b, c; int mean; a = 40; b = 50; c = 60; mean = (a + b +c) / 3; a b c mean a b c mean Overview 5
6 Variables float Type int a, b, c; float mean; a = 45; b = 53; c = 63; mean = (a + b +c) / 3.0; a b c mean a b c mean float type Overview 6
7 C and assembly code view of variables variable name variable value address data a 40 b c mean c source code view Compiler assembly code view Overview 7
8 Memory : (Address, Data) a address address data a value b address b value c address mean address c value mean value compiler determines the addresses Overview 8
9 Getting the addresses of variables &variable address Addresses determined by a compiler &a address of a &b address of b &c address of c &mean address of mean Overview 9
10 Example: a variable stored in memory &variable address int a; a = 40; &a a &a a :address (where) :data (what) Overview 10
11 Variables and the & operator int int a=40, b=50, c=60; mean=(a+b+c)/3; address data &a: 4500 a: 40 a b &b: 4510 &c: 4520 b: 50 c: 60 c 60 &mean: 4530 mean: 50 mean 50 Overview 11
12 Graphical representation of address assignment a = 40; Value assignment to a int a ; &a: 4500 a = 40 integer variable an arrow a pointer p = &a; Address assignment to p int * p ; &p p= &a pointer variable 4500 Overview 12
13 Data and Address Operators Address operator Data operator &variable address *address data &a address of a *(&a) data at the address of a &b address of b *(&b) data at the address of b &c address of c *(&c) data at the address of c &mean address of mean *(&mean) data at the address of mean Overview 13
14 The & and * operators The address of a variable : Address of operator & the value at an address : Dereferencing operator * * & a a p *p & Overview 14
15 &a and *p &a *p a must be a variable p s value must be an address int a ; int * p ; integer variable a pointer variable p Overview 15
16 The address &a and the variable *p &a an address *p a variable a a variable p an address int a ; int * p ; integer variable a pointer variable p Overview 16
17 R/W Accessing &a and *p int a ; int * p ; integer variable a pointer variable p & a = (write) * p = (write)... = & a (read)... = * p (read) like a constant like a variable Overview 17
18 &a and *p examples * & a a p *p & The value of p is an address. The data at that address is *p &p p & int a ; int * p ; integer variable a pointer variable p Overview 18
19 The & and * operators [int a] * & a a & a a & *(& a) = a int a ; integer variable a int a ; integer variable a Overview 19
20 The & and * operators [int *p] * p *p p *p & * & p p & p p & int * p ; pointer variable p int * p ; pointer variable p Overview 20
21 The & and * operators [int *p] * p *p p *p & &(*p) = p *(p) = *p * & p p & p p & &(p) = &p *(&p) = p value of p ( an address) value of p ( an address) Overview 21
22 The & and * operators [int *p] The address of a variable : Address of operator & &(p) = &p &(*p) = p the value at an address : Dereferencing operator * *(&p) = p *(p) = *p int * p ; pointer variable p int * p ; pointer variable p Overview 22
23 The & and * cancel each other &(*p) = p *(& p) = p [2] * & p p & p p *(& p) = p [1] & [1] * p *p &(*p) = p p *p [2] & Overview 23
24 Pointer Type Declaration int a; &a a a holds integer value int *p; &p p p holds address *p holds integer value p *p value of p ( an address) Overview 24
25 Address assignment to a pointer variable int *p; p = &a; Address assignment where: the address of p what: the value of p &a (address of a) The value of p is the address &a p points to &a p points to where the variable a is stored Overview 25
26 Address assignment example int *p; address data p = &a; Address assignment &a: 4500 &b: 4510 a: 40 b: 50 &c: 4520 c: 60 &mean: 4530 mean: 50 &p: 4540 p: 4500 Overview 26
27 Value assignment to a pointer variable int *p; p = &a; *p = 55; Value assignment where: the location where the value of p points to (value of p address) what: the data at p 55 (an integer value) Overview 27
28 Value assignment to a pointer variable int *p; address data p = &a; *p = 55; Value assignment p: &a: 4500 &b: 4510 *p: a: 55 b: 50 &c: 4520 c: 60 &mean: 4530 mean: 50 &p: 4540 p: 4500 Overview 28
29 Function examples passing values function call int x=3, y=5;... S = vsum ( x,... y); &x &y x y int vsum (int a, int b) { } return (a + b); function definition &a &b a=x b=y Overview 29
30 Function examples passing addresses function call int x=3, y=5;... S = asum ( &x,... &y); &x &y x y int asum (int *a, int *b) { } return (*a + *b); function definition &a &b a=&x b=&y Overview 30
31 Comparison int x, y; int x, y;... S = vsum ( x, y); S = asum ( &x, &y);... int vsum (int a, int b) { int asum (int *a, int *b) { } return (a + b); } return (*a + *b); a = x; b = y; a + b = x + y a = &x; b = &y *a = *(&x); *b = *(&y) *a + *b = x + y Overview 31
32 1-way vs. 2-way int x, y; int x, y; S = vsum ( x, y); S = asum ( &x, &y); int vsum (int a, int b) { int val = a + b; int asum (int *a, int *b) { int val = *a + *b; } a = b = 0; return (val); } *a = *b = 0; return (val); *(&x) = *(&y) = x = y = 0 a = x; b = y; a = 0 b = 0 a = &x; b = &y x = *(&x) = *a = 0 y = *(&y) = *b = 0 Overview 32
33 Differences int x, y; int x, y; S = vsum ( x, y); S = asum ( &x, &y); int vsum (int a, int b) { int val = a + b; int asum (int *a, int *b) { int val = *a + *b; } a = b = 0; return (val); } *a = *b = 0; return (val); *(&x) = *(&y) = x = y = 0 x, y : no change x, y : changed to zeros Overview 33
34 printf() : the built-in function Expected Output The mean of three numbers a = 40 b = 50 c = 60 mean(40, 50, 60) => 50 printf( The mean of three numbers \n ); printf( a = %d \n, a); printf( b = %d \n, b); printf( c = %d \n, c); printf( mean (%d, %d, %d) => %d \n, a, b, c, mean); Overview 34
35 scanf() : another built-in function Input Example Enter three numbers! a = 40 b = 50 c = 60 address &a: 4500 value 40 &b: &c: printf( Enter three numbers! \n ); printf( a = ); scanf( %d, &a); printf( b = ); scanf( %d, &b); printf( c = ); scanf( %d, &c); Overview 35
36 The Main Function (1) main (void) { int a, b, c; int mean; } a = 40; b = 50; c = 60; mean = (a + b + c) / 3; printf( The mean of three numbers \n ); printf( a = %d \n, a); printf( b = %d \n, b); printf( c = %d \n, c); printf( mean (%d, %d, %d) => %d \n, a, b, c, mean); Overview 36
37 The Main Function (2) main (void) { int a, b, c; int mean; } printf( Enter three numbers! \n ); printf( a = ); scanf( %d, &a); printf( b = ); scanf( %d, &b); printf( c = ); scanf( %d, &c); mean = (a + b + c) / 3; printf( The mean of three numbers \n ); printf( a = %d \n b = %d \n c = %d \n, a, b, c); printf( mean (%d, %d, %d) => %d \n, a, b, c, mean ); Overview 37
38 The Main Function (3) main (void) { int a, b, c; int mean; get_numbers(? ); compute_mean(? ); print_numbers(? ); } Overview 38
39 Function compute_mean() int compute_mean (int x, int y, int z) ; function prototype main (void) { int mean; mean = compute_mean(40, 50, 60); * Call by Value } int values are copied int compute_mean (int x, int y, int z) { int avg; * Local Variable avg = (x + y + z) / 3; return( avg ); * Return Value } Overview 39
40 Function get_numbers() void get_numbers (int *x, int *y, int *z) ; function prototype main (void) { int a, b, c; get_numbers(&a, &b, &c); * Call by Reference } addresses are copied void get_numbers (int * x, int * y, int * z) { printf( Enter three numbers! \n ); printf( a = ); scanf( %d, x); printf( b = ); scanf( %d, y); printf( c = ); scanf( %d, z); } * No Return Value Overview 40
41 Call by Value & Call by Reference * Call by Value mean = compute_mean(40, 50, 60); int compute_mean (int x, int y, int z) &x x=40 &y y=50 &z z=60 * Call by Reference get_numbers(&a, &b, &c); &a 40 &b 50 &c 60 void get_numbers (int * x, int * y, int * z) &x x=&a &y y=&b &z z=&c Overview 41
42 Change the caller s variables * Call by Reference address value &a 40 &b 50 &c 60 Caller s Variables &x x=&a &y y=&b &z z=&c Now, values of a, b, c are changed in the get_numbers() function *x= 100; *y= 200; *z= 300; a= 100; b= 200; c= 300; The callee can change the values of the caller s variables &a 100 &b 200 &c 300 Overview 42
43 Function print_numbers() void print_numbers (int x, int y, int z, int avg) { printf( The mean of three numbers \n ); printf( a = %d \n b = %d \n c = %d \n, x, y, z); printf( mean (%d, %d, %d) => %d \n, x, y, z, avg); } * Call by Value * No Return Value main (void) { int a, b, c; int mean; } print_numbers(a, b, c, mean); Overview 43
44 The Main Function (4) void get_numbers (int *x, int *y, int *z); int compute_mean (int x, int y, int z); void print_numbers (int x, int y, int z, int avg); Prototypes main (void) { int a, b, c; int mean; get_numbers(&a, &b, &c); mean = compute_mean(a, b, c); } print_numbers(a, b, c, mean); Overview 44
45 Pointers and Arrays p+0 p+1 p+2 *(p+0) *(p+1) *(p+2) a+0 a+1 a+2 *(a+0) *(a+1) *(a+2) a[0] a[1] a[2] & p p int * p ; int a[3] ; pointer variable p array name a Overview 45
46 The Main Parameters (1) #include <stdio.h> int main(int argc, char *argv[]) { int i; printf("argc= %d \n", argc); for (i=0; i<argc; ++i) { } printf("argv[%d] = %s \n", i, argv[i]); } Overview 46
47 The Main Parameters (2) ~ $./a.out argc= 1 argv[0] =./a.out young@usys ~ $./a.out one two three argc= 4 argv[0] =./a.out argv[1] = one argv[2] = two argv[3] = three young@usys ~ $./a.out one two three four argc= 5 argv[0] =./a.out argv[1] = one argv[2] = two argv[3] = three argv[4] = four Overview 47
48 The Main Parameters (3) ~ $./a.out one two argc= 3 argv[0] =./a.out argv[1] = one argv[2] = two. argv[0] / argv[1] argv[2] t w o o n e \0 a. o u t \0 \0 Overview 48
49 References [1] Essential C, Nick Parlante [2] Efficient C Programming, Mark A. Weiss [3] C A Reference Manual, Samuel P. Harbison & Guy L. Steele Jr. [4] C Language Express, I. K. Chun
Overview (1A) Young Won Lim 9/14/17
Overview (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationOverview (1A) Young Won Lim 9/9/17
Overview (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationPointers (1A) Young Won Lim 1/5/18
Pointers (1A) Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationPointers (1A) Young Won Lim 1/9/18
Pointers (1A) Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationPointers (1A) Young Won Lim 11/1/17
Pointers (1A) Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationApplications of Pointers (1A) Young Won Lim 12/26/17
Applications of (1A) Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any
More informationPointers (1A) Young Won Lim 3/5/18
Pointers (1A) Copyright (c) 2010-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationPointers (1A) Young Won Lim 1/14/18
Pointers (1A) Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationPointers (1A) Young Won Lim 12/4/17
Pointers (1A) Coyright (c) 2010-2017 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationFunction Overview (1A) Young Won Lim 10/23/17
Function Overview (1A) Copyright (c) 2010 2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or
More informationApplications of Pointers (1A) Young Won Lim 3/14/18
(1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished
More informationApplications of Pointers (1A) Young Won Lim 3/21/18
(1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished
More informationApplications of Pointers (1A) Young Won Lim 4/11/18
(1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished
More informationApplications of Pointers (1A) Young Won Lim 3/31/18
(1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished
More informationPointers (1A) Young Won Lim 10/18/17
Pointers (1A) Coyright (c) 2010-2013 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationApplications of Pointers (1A) Young Won Lim 4/24/18
(1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version ublished
More informationApplications of Pointers (1A) Young Won Lim 2/27/18
Alications of (1A) Coyright (c) 2010-2018 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationPointers (1A) Young Won Lim 1/22/18
Pointers (1A) Copyright (c) 2010-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationPointers (1A) Young Won Lim 2/6/18
Pointers (1A) Copyright (c) 2010-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationApplications of Structures (1A) Young Won Lim 12/4/17
Applications of (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any
More informationPointers (1A) Young Won Lim 10/23/17
Pointers (1A) Coyright (c) 2010-2013 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationApplications of Pointers (1A) Young Won Lim 1/5/18
Alications of (1A) Coyright (c) 2010-2017 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationApplications of Structures (1A) Young Won Lim 12/8/17
Applications of (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any
More informationPointers (1A) Young Won Lim 2/10/18
Pointers (1A) Copyright (c) 2010-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationApplications of Arrays (1A) Young Won Lim 2/11/17
Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published
More informationApplications of Arrays (1A) Young Won Lim 3/15/17
Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published
More informationArrays (1A) Young Won Lim 12/4/17
Arrays (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationStructure (1A) Young Won Lim 7/30/13
Structure (1A) Copyright (c) 2010 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationMemory Arrays (4H) Gate Level Design. Young Won Lim 3/15/16
Arrays (4H) Gate Level Design Young Won Lim 3/15/16 Copyright (c) 2011, 2016 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation
More informationArrays (1A) Young Won Lim 1/27/17
Arrays (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationFile (1A) Young Won Lim 11/25/16
File (1A) Copyright (c) 2010-2016 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationExample 1. Young Won Lim 11/17/17
Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published
More informationExample 1 : using 1-d arrays. Young Won Lim 12/13/17
: using 1-d arrays Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any
More informationType (1A) Young Won Lim 2/17/18
Type (1A) Copyright (c) 2010-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationExample 2. Young Won Lim 11/24/17
Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published
More informationExample 3 : using a structure array. Young Won Lim 11/25/17
: using a structure array Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2
More informationStructures (1A) Young Won Lim 12/4/17
Structures (1A) Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationStructures (1A) Young Won Lim 11/8/16
Structures (1A) Copyright (c) 2010-2016 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationExample 3. Young Won Lim 11/22/17
Copyright (c) 2010-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published
More informationMemory (1A) Young Won Lim 9/7/17
(1A) Copyright (c) 21-26 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published
More informationNumber System (1A) Young Won Lim 7/7/10
Number System (A) 7/7/ Copyrigt (c) 9-6 Young W. Lim. Permission is granted to copy, distribute and/or modify tis document under te terms of te GNU ree Documentation License, Version. or any later version
More informationArrays and Strings (2H) Young Won Lim 3/7/18
Arrays and Strings (2H) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or
More informationVariables (2D) Young Won Lim 3/28/18
Variables (2D) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationELF (1A) Young Won Lim 10/22/14
ELF (1A) Copyright (c) 2010-2014 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationApplications of Array Pointers (1A) Young Won Lim 11/22/18
Appliations of Array Pointers (1A) Copyright () 2010-2018 Young W. Lim. Permission is granted to opy, distribute and/or modify this doument under the terms of the GNU Free Doumentation Liense, Version
More informationBIL 104E Introduction to Scientific and Engineering Computing. Lecture 14
BIL 104E Introduction to Scientific and Engineering Computing Lecture 14 Because each C program starts at its main() function, information is usually passed to the main() function via command-line arguments.
More informationPointers (2G) Young Won Lim 3/7/18
Pointers (2G) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationExpressions (2E) Young Won Lim 4/9/18
Expressions (2E) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationProgram Structure (2A) Young Won Lim 3/8/18
Program Structure (2A) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or
More informationAccessibility (1A) Young Won Lim 8/22/13
Accessibility (1A) Copyright (c) 2011-2013 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any
More informationExpressions (2E) Young Won Lim 3/10/18
Expressions (2E) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationDay05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14
Day05 A Young W. Lim 2017-10-07 Sat Young W. Lim Day05 A 2017-10-07 Sat 1 / 14 Outline 1 Based on 2 Structured Programming (2) Conditions and Loops Conditional Statements Loop Statements Type Cast Young
More informationStack Tutorial. Young W. Lim Sat. Young W. Lim Stack Tutorial Sat 1 / 15
Stack Tutorial Young W. Lim 2016-10-15 Sat Young W. Lim Stack Tutorial 2016-10-15 Sat 1 / 15 Outline 1 Introduction References Stack Background Transferring Control Young W. Lim Stack Tutorial 2016-10-15
More informationDay02 A. Young W. Lim Sat. Young W. Lim Day02 A Sat 1 / 12
Day02 A Young W. Lim 2017-10-07 Sat Young W. Lim Day02 A 2017-10-07 Sat 1 / 12 Outline 1 Based on 2 Introduction (2) - Basic Elements Basic Elements in C Programming Young W. Lim Day02 A 2017-10-07 Sat
More informationProgram Structure (2A) Young Won Lim 5/28/18
Program Structure (2A) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or
More informationARM Assembly Exercise (1B) Young Won Lim 7/16/16
ARM Assembly Exercise (1B) Copyright (c) 2014-2016 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2
More informationELF (1A) Young Won Lim 3/24/16
ELF (1A) Copyright (c) 21-216 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationClass (1A) Young Won Lim 9/8/14
Class (1A) Copyright (c) 2011-2013 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationFriday, September 16, Lab Notes. Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week
Friday, September 16, 2016 Lab Notes Topics for today Redirection of input and output Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week 1. Redirection
More informationStack Debugging. Young W. Lim Thr. Young W. Lim Stack Debugging Thr 1 / 12
Stack Debugging Young W. Lim 2017-07-13 Thr Young W. Lim Stack Debugging 2017-07-13 Thr 1 / 12 Outline 1 Introduction References Compiling to IA32 Assembly Checking /proc//maps file Young W. Lim Stack
More informationFunctions (4A) Young Won Lim 3/16/18
Functions (4A) Copyright (c) 2015 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationMemory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)
Memory Allocation Memory What is memory? Storage for variables, data, code etc. How is memory organized? Text (Code) Data (Constants) BSS (Global and static variables) Text Data BSS Heap Stack (Local variables)
More informationAlgorithms Bubble Sort (1B) Young Won Lim 4/5/18
Algorithms Bubble Sort (1B) Young Won Lim 4/5/18 Copyright (c) 2017 2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation
More informationAMCAT Automata Coding Sample Questions And Answers
1) Find the syntax error in the below code without modifying the logic. #include int main() float x = 1.1; switch (x) case 1: printf( Choice is 1 ); default: printf( Invalid choice ); return
More informationLecture 16. Daily Puzzle. Functions II they re back and they re not happy. If it is raining at midnight - will we have sunny weather in 72 hours?
Lecture 16 Functions II they re back and they re not happy Daily Puzzle If it is raining at midnight - will we have sunny weather in 72 hours? function prototypes For the sake of logical clarity, the main()
More informationPointers and scanf() Steven R. Bagley
Pointers and scanf() Steven R. Bagley Recap Programs are a series of statements Defined in functions Can call functions to alter program flow if statement can determine whether code gets run Loops can
More informationFriday, February 10, Lab Notes
Friday, February 10, 2017 Lab Notes Topics for today Structures in C Redirection of input and output in a Unix-like environment Command line arguments More pre-processor options Programs: Finish Program
More informationStructures (2I) Young Won Lim 4/17/18
Structures (2I) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationProcedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29
Procedure Calls Young W. Lim 2017-08-21 Mon Young W. Lim Procedure Calls 2017-08-21 Mon 1 / 29 Outline 1 Introduction Based on Stack Background Transferring Control Register Usage Conventions Procedure
More informationFunctions (4A) Young Won Lim 5/8/17
Functions (4A) Copyright (c) 2015 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationGDB Tutorial. Young W. Lim Tue. Young W. Lim GDB Tutorial Tue 1 / 32
GDB Tutorial Young W. Lim 2017-02-14 Tue Young W. Lim GDB Tutorial 2017-02-14 Tue 1 / 32 Outline 1 Introduction Young W. Lim GDB Tutorial 2017-02-14 Tue 2 / 32 Based on "Self-service Linux: Mastering the
More informationmith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut
mith College CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 2 Hours D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to Assembly Unix Standard
More informationC BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.
C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,
More informationArrays and Pointers (part 2) Be extra careful with pointers!
Arrays and Pointers (part 2) EECS 2031 22 October 2017 1 Be extra careful with pointers! Common errors: l Overruns and underruns Occurs when you reference a memory beyond what you allocated. l Uninitialized
More informationStructures (2I) Young Won Lim 3/7/18
Structures (2I) Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationArrays and Pointers (part 2) Be extra careful with pointers!
Arrays and Pointers (part 2) CSE 2031 Fall 2011 23 October 2011 1 Be extra careful with pointers! Common errors: Overruns and underruns Occurs when you reference a memory beyond what you allocated. Uninitialized
More informationAlgorithms (7A) Young Won Lim 4/10/17
Algorithms (7A) Copyright (c) 2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationMonad Background (3A) Young Won Lim 11/20/17
Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published
More informationBinghamton University. CS-211 Fall Functions. The Basis of C
Functions The Basis of C 1 What is a function? Have you ever needed to convert from C to F? Demo: http://www.pronk.com/samples/projects/021$function_machine/fu nction_machine.html 2 Function in C float
More informationProgramming and Data Structure
Programming and Data Structure Sujoy Ghose Sudeshna Sarkar Jayanta Mukhopadhyay Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur Spring Semester 2012 Programming and Data
More informationHW / SW Implementation Overview (0A) Young Won Lim 7/16/16
HW / SW Implementation Copyright (c) 213-216 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any
More informationCourse organization. Course introduction ( Week 1)
Course organization Course introduction ( Week 1) Code editor: Emacs Part I: Introduction to C programming language (Week 2-9) Chapter 1: Overall Introduction (Week 1-3) Chapter 2: Types, operators and
More informationAlgorithms (7A) Young Won Lim 4/18/17
Algorithms (7A) Copyright (c) 2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationSU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)
SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar) 1 Problem A 1.1 Specification Write an ANSI-C program that reads input from the
More informationStack Debugging. Young W. Lim Sat. Young W. Lim Stack Debugging Sat 1 / 40
Stack Debugging Young W. Lim 2017-07-22 Sat Young W. Lim Stack Debugging 2017-07-22 Sat 1 / 40 Outline 1 Introduction References Compiling to IA32 Assembly Checking /proc//maps file Checking Stack
More informationC-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga
C-Programming CSC209: Software Tools and Systems Programming Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Adapted from Dan Zingaro s 2015 slides. Week 2.0 1 / 19 What
More informationCSC258: Computer Organization. Functions and the Compiler Tool Chain
CSC258: Computer Organization Functions and the Compiler Tool Chain 1 A Note about This Week s Quiz There were very few exercises this week, except for writing substantial pieces of code. Instead, I provided
More informationGHCi: Getting started (1A) Young Won Lim 5/26/17
GHCi: Getting started (1A) Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2
More informationFrom Java to C. Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides
From Java to C Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides 1 Outline Overview comparison of C and Java Good evening Preprocessor
More informationPROGRAMMAZIONE I A.A. 2017/2018
PROGRAMMAZIONE I A.A. 2017/2018 FUNCTIONS INTRODUCTION AND MAIN All the instructions of a C program are contained in functions. üc is a procedural language üeach function performs a certain task A special
More informationArrays and Pointers. CSE 2031 Fall November 11, 2013
Arrays and Pointers CSE 2031 Fall 2013 November 11, 2013 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 Arrays: Example
More informationPolymorphism Overview (1A) Young Won Lim 2/20/18
Polymorphism Overview (1A) Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2
More informationare all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable.
CMPS 12M Introduction to Data Structures Lab Lab Assignment 3 The purpose of this lab assignment is to introduce the C programming language, including standard input-output functions, command line arguments,
More informationDynamic memory allocation
Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes
More informationStructured Programming. Functions and Structured Programming. Functions. Variables
Structured Programming Functions and Structured Programming Structured programming is a problem-solving strategy and a programming methodology. The construction of a program should embody topdown design
More informationMonad (1A) Young Won Lim 6/9/17
Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published
More informationWorksheet 4 Basic Input functions and Mathematical Operators
Name: Student ID: Date: Worksheet 4 Basic Input functions and Mathematical Operators Objectives After completing this worksheet, you should be able to Use an input function in C Declare variables with
More informationSU 2017 May 18/23 LAB 3 Bitwise operations, Program structures, Functions (pass-by-value), local vs. global variables. Debuggers
SU 2017 May 18/23 LAB 3 Bitwise operations, Program structures, Functions (pass-by-value), local vs. global variables. Debuggers 1. Problem A Pass-by-value, and trace a program with debugger 1.1 Specification
More informationArrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014.
Arrays Arrays and Pointers l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. EECS 2031 Fall 2014 November 11, 2013 1 2 Arrays: Example
More informationSide Effects (3B) Young Won Lim 11/20/17
Side Effects (3B) Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More information