C Programming - AndroBench

Pointers Review recursion scoping rule enforced by auto class solution formation arrays and pointers

call-by-reference Relation between Arrays and Pointers int a[10], i; a[i] is equivalent to *(a + i)

int i, *p p[i] is equivalent to *(p + i) a + i is equivalent to &a[i] Arrays as Function Arguments When an array is passed as an argument t o a function, the base address value is pas sed. the array elements are not copied

equivalent function headers double sum(double a[], int n); double sum(double *a, int n) Dynamic Memory Allocation The standard C lib contains void *calloc(int n, int m); void *malloc(int m);

if failed, NULL is returned calloc (n, m) is equivalent to p = malloc (n*m); memset(p, 0, m*n); - what is p+2? Memory Release Youd better free the allocated space

free(p); p must be the pointer to the space allocated by calloc() or malloc() If you forget to free, it will be freed when the process exits for some systems like Linux, Windows for some other systems, nothing is guaranteed

Strings review char *s = abcde; char s[] = abcde; char s[] = {a, b, c, d, e, \0}; you s

are a fool \0 String Functions ANSI C Lib contains many useful functions char *strcat(char *s1, const char *s2);

result is in *s1 what if there is no space after s1? strncat( dest, src, n);

char * const a; /* can change char but NOT pointer */ return value == s1 /* why do we neet it */ int strcmp(const char *s1, const char *s2); returns negative, zero, positive depending on the lexic ographical order char *strcpy(char *s1, const char *s2); copy s2 to s1

what if s2 is longer than s1? strncpy(dest, src, strlen(dest)); /* safe */ size_t strlen(const char *s); size_t is usually unsigned int S h

a p p y

\0 e n d i

n g S1 h

a p p y \0

S2 e n d \0

Multidimensional Arrays int a[3][4] row column the base address is &a[0][0], NOT a what is a[1] ?

You can expand it to three dimensional arr ays int a[3][5] a[2][3] is equivalent to *(a[2] + 3) (*(a + 2))[3]

*((*(a+2)) + 3) *(&a[0][0] + 5*2 + 3) Initialization Arrays of Pointers char *w[N]; an array of pointers each pointer is to char

ragged array char *p[2] = {abc, 1234567890}; read the sort_words example in the textbook Arguments to main( ) int main(int argc, char **argv) argc and argv are used for main() argc is the number of arguments

argv is an array of pointers argv[0] is the name of the main program then naturally, argc >= 1 argc = 5 argv[0] = my_echo argv[1] = midterm argv[2] = is argv[3] = on

argv[4] = Thursday Functions as Arguments a function name can be passed as an argument think a function name as a pointer (like an array) (*f)(x) f is a pointer to a function *f is a function (*f)(x) is a call to the function

if you are still confused, just follow the example Functions as Arguments prototypes const volatile const int N = 3; N cannot be changed after initialization

N cannot be used for array definition like int k[N]; with pointers int *const ptr; const int* ptr; volatile int *p; telling a compiler NOT to change order,

cacheing or anything related to the integer since it may be changed by an external event void SendCommand (int * hwstatus, int command, int data) { // wait while the gadget is busy: while (hwstatus == isbusy) { // do nothing here.

} // set data first: hwdata = data; // writing the command starts the action: hwcommand = command; }

Recently Viewed Presentations

  • Chapter Three: Supporting Details

    Chapter Three: Supporting Details

    After Rudy _____ his 11 p.m. curfew—breezing in at 2 a.m. with a cheerful "Hi, folks!"—his parents took away his car keys for a month. Complete each item with the correct word from the box. A. complement B. discreet C....
  • SYDE 575: Introduction to Image Processing

    SYDE 575: Introduction to Image Processing

    and filter function . h. ... (DoG), Gabor, Laplacian of Gaussian. Periodic noise filtering (Section 5.4) Blurring/Noise reduction. Noise characterized by sharp transitions in image intensity. ... SYDE 575: Introduction to Image Processing Last modified by:
  • Introducing a New Product - Henry County School District

    Introducing a New Product - Henry County School District

    The Hopi (Southwest Desert) Fourth Grade Ms. Alvarado The Hopi (Southwest Desert) Region: Southwest Desert ("I hopi I don't sit on a cactus!") Name:It's pronounced "hope-ee," and it means "peaceful person" or "civilized person" in the Hopi language Shelter: pueblos...
  • Efficient and Fair Multi-programming in GPUs via Effective ...

    Efficient and Fair Multi-programming in GPUs via Effective ...

    This work was jointly performed with my advisor and colleagues . at The College of William and Mary . and . our collaborators at AMD and University of Rochester. Finite State Machine (Automata) Processing ... LV Bro217 GeoMean 29.6117255560074 3.6897164620613201...
  • GS1 Industry & Standards Event 2018 10-14 September 2018 ...

    GS1 Industry & Standards Event 2018 10-14 September 2018 ...

    It represents a challenge for all types of company everywhere in the world. In BtoC sector, we can track our plane before take-off, we can track a parcel until delivery at our doors, we know where and how the chicken...
  • CCC CONFER Crash Course - CCSF

    CCC CONFER Crash Course - CCSF

    Arial Default Design Crash Course What is CCC Confer CCC Confer Products Call and Confer Meet and Confer Office Hours Getting Started Slide 8 Getting Started Scheduling Options Live Captions Slide 12 Quick Participant Orientation Participant Orientation Elluminate NOTABLE FEATURES...
  • Long Distance Trade: The Silk, Sand, and Sea Roads

    Long Distance Trade: The Silk, Sand, and Sea Roads

    Trans- Saharan trade route ( also known as the sand road) linked North Africa, Sub-Saharan Africa, and the Mediterranean. B) Trans-Saharan trade would not have been possible without the domesticated . camel. Caravans were large, organized groups of traders that...
  • PowerPoint - Washoe County, Nevada

    PowerPoint - Washoe County, Nevada

    Tianyu was responsible for most of the logistic details (marketing, ticket sales, parking, daily clean-up/etc.) The agreement called for a 90/10 split of gross tickets sales. ... Template for pages 1-9. Dragon Lights Reno 2018. Template for pages 1-9.