









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to the c programming language, comparing it to java and covering the basics through lectures and examples. Topics include data types, operators, control structures, preprocessor, command line arguments, arrays, structures, pointers, and dynamic memory. It is recommended to read the k&r c book for further details.
Typology: Study notes
1 / 17
This page cannot be seen from the preview
Don't miss anything!










Acknowledgement: These slides are adapted from lecture slides made available by Prof. Dave O’ Halloran (Carnegie Mellon University)
#include <stdio.h> int main(int argc, char argv[]) { / print a greeting / printf("Good evening!\n"); return 0; } $ ./goodevening Good evening! $*
#define CS367
“Computer Systems & Programming\n" int main(int argc, char argv[]) { printf(CS367); return 0; }*
int main(int argc, char argv) { printf(”Computer Systems & Programming\n"); return 0; }*
#define CS int main(int argc, char argv) { #ifdef CS printf("Computer Systems & Programming\n"); #else printf("Some other class\n"); #endif return 0; }*
int main(int argc, char argv) { printf(“Computer Systems & Programming\n"); return 0; }*
$ ./cmdline Computer Systems and Programming 5 arguments 0: ./cmdline 1: Computer 2: Systems 3: and 4: Programming $
**f_addr = 3.2; / indirection operator / float g = f_addr;/ indirection: g is now 3.2 / f = 1.3; / but g is still 3.2 / f (^) f_addr 4300 4304
f (^) f_addr 4300 4304
void swap_1(int a, int b) { int temp; temp = a; a = b; b = temp; } Q: Let x=3, y=4, after swap_1(x,y); x =? y=? A1: x=4; y=3; A2: x=3; y=4;
**void swap_2(int *a, int *b) { int temp; temp = *a; *a = b; b = temp; } Q: Let x=3, y=4, after swap_2(&x,&y); x =? y=? A1: x=3; y=4; A2: x=4; y=3;