Summary CSE 2031 Fall 20101 1102022 C Basics
Summary CSE 2031 Fall 20101 1/10/2022
C Basics • • Data types and type conversion Precedence and order of evaluation Control flows Functions – Passed by value – Passed by reference • I/O: getchar, printf, scanf • File access 2
Precedence and Order of Evaluation 33
Structures • Structures and functions • Arrays of structures • Pointers to structures – Passed by value – Passed by reference • Self-referential structures (linked lists) 4
Pointers • • • Function arguments Relationship with arrays Address arithmetic Strings (char pointers) Arrays of pointers; pointers to pointers – char *p 1[10] versus char (*p 2)[10] • Pointers and 2 D-arrays • Dynamic memory allocation • Command-line arguments 5
UNIX • Basic UNIX commands • Shell scripting (all) • How to study: first learn the basics then … – Step 1: for each example/script, describe in detail what the script does, what will be printed. – Step 2: (a couple of days later) read the problem descriptions, write the scripts (without looking at the lecture notes) and make them run. 6
During the exam … • No questions • You will be given – Table of precedence – ASCII code table – UNIX reference sheets 7
Pointers and Arrays int a[10], *pa; pa = a; /* same as pa = &a[0]*/ pa++; /*same as pa = &a[1]*/ a[i] &a[i] pa[i] *(a+i) a+i *(pa+i) Notes a = pa; a++; are illegal. Think of a as a constant, not a var. p[-1], p[-2], etc. are syntactically legal. 88
Arrays of Pointers: Example char *words[] = { “apple”, “cherry”, “prune” }; +1 char **p; p = words; printf("%cn", **p); printf("%cn", *(*(p+1)+2)); printf("%cn", *(*(p+2)+2)+1); 99
- Slides: 9