!! " # & / / 3 * (4 $ 5 & # #! ' $ % -!! )! 1 1 ' $ & % $ 3! : ;, ; + 3 < % 3 ( (! % #, < 1 < $ 3! # 3 < ' "

Size: px
Start display at page:

Download "!! " # & / / 3 * (4 $ 5 & # #! ' $ % -!! )! 1 1 ' $ & % $ 3! : ;, ; + 3 < % 3 ( (! % #, < 1 < $ 3! # 3 < ' ""

Transcription

1 #"$)(+-,#.)/ :1; <-:1; = >? B C DFEG H IJ K# L M#N " # $ " $ ( ) (+, -. / / $ (0. # 1 2 ( # " 3 4 DFEG H IJPOQ I R TS U VEW G # / / 3 (4 $ 5 # # $ - ) $ 3 : ;, ; + 3 < 3 ( ( < = 8 9 #, < 1 < $ 3 # 3 < 5 6 1

2 U VEW G EW G $ 3 $ >,?, > 3 $ 3 $ ) A # B 5 ; A $ / C ; C 9 " B : 3 < / / $ E $ 3 (6 7 D 9 E ( E(" / / 7 8 U S 7 9 C 9 5 : B E # ( F G" H ( / / I / / J F G 9 10 B T I I P I Q I H H $ ( : ( 3 < ( 3 (3 (0 ( ( / / ( (# = (, ( (; (0 K # 3 3 (I K # 3 E / (A A ( < S < ( <

3 S S / / E O P ( 9 ( ( L 9 M N S U java StartClass " StartClass.main I # J B main() B. ( " B.( S public class hello { public static void main (String args []) { System.out.println ( Hello world ); int main(int argc, char argv[]) { puts( Hello, World ); return 0; struct list{int data; struct list next; struct list start, end; void add(struct list head, struct list list, int data; int delete(struct list head, struct list tail); void main(void){ start=end=null; add(start, end, 2); add(start, end, 3); printf( First element: d, delete(start, end)); void add(struct list head, struct list tail, int data{ if(tail==null){ head=tail=malloc(sizeof(struct list)); head->data=data; head->next=null; else{ tail->next= malloc(sizeof(struct list)); tail=tail->next; tail->data=data; tail->next=null;

4 void delete (struct list head, struct list tail){ struct list temp; if(head==tail){ free(head); head=tail=null; else{ temp=head->next; free(head); head=temp; void main(void) { printf( Hello World. \n \t and you \n ); / print out a message / return; 19 $Hello World. and you $ 20 Q I E T U H TQ I E U stdio.h Q + 3 B void main(void){ printf( / message you want printed / ); \n A (\t A R printf. printf( Have you heard of \ The Rock\? \n ); int main(int argc, char argv[]) int 9 (> TQ I U TQ I U + / S. 6 T = U H argc 4 argv ( int main() { puts( Hello World ); exit(0); ) exit() B. a.out 1 23 third arg

5 TQ I U TQ I U (, ( (E B E foo.java foo.class I # " foo.c a.out a.out x.pl x.java x.c, x.cc perl javac gcc, g++ data args results java a.out E Q U.H QQ QQ ". F G $ gcc hello.c $ a.out Hello, World $ E B B I QQ U I IJQQ,? B. " gcc o hello hello.o 3 " gcc c a.c. gcc c b.c. gcc o hello a.o b.o ) gcc o calc calc.c -lm # "

6 U I IJQQ QQ gcc ( ( B gcc H B 5 if (x = 0).if (x == 0) E ) " undefined symbol first referenced in file _print program.o ld fatal: Symbol referencing errors No output written to file U U Q U U Q, 1 #define MAXVALUE 100 #define check(x) ((x) < MAXVALUE) if (check(i) { if ((i) < 100) { Q ( gcc E U U Q U U Q #define #define 6 ( T (0 #undef symbol 1 #define MAXLEN getchar(), putchar() H " #define valid(x) ((x) > 0 (x) < 20) if (valid(x++)) { valid(x++) -> ((x++) > 0 (x++) < 20)

7 U U Q - T.H I Q H B I #include filename.h #include <filename.h> F G L > /usr/include gcc I. 1 #include mydefs.h #include /home/alice/program/defs.h U U Q Q I L I H Q U.H I #if expression code segment 1 #else code segment 2 #endif " ( 6 ( T " B - #define OS linux #if OS == linux puts( Linux ); #else puts( Something else ); #endif U U Q VA T B Q IJU U Q : ( #ifdef name code segment 1 #else code segment 2 #endif " #define USEDB ( 6 ( T 3 Q +, 6 8 > Q # K > Q ( > > I (. (? I B QT G U / any text until / // / / B - / /( / / / AverageGrade() Given an array of grades, compute the average. / B ( ". (. 6 T V D V D 6 T D 0 6 T C 8 W W = W W = W "# $# "# $#

8 IJT G U ; B int F G 2 (..(8 V 8 V ( int A = T (long A 8 V (unsigned ( char A 6 F G ( void main(void) { int nstudents = 0; / Initialization, required / printf( How many students does Columbia have?: ); scanf ( d, nstudents); / Read input / printf( Columbia has d students.\n, nstudents); return ; $ How many students does Columbia have?: (enter) Columbia has students LG U Q I B I TU H Q I U H Q Q I B I void main(void) { int i,j = 12; / i not initialized, only j / float f1,f2 = 1.2; i = (int) f2; / explicit: i <- 1, 0.2 lost / f1 = i; / implicit: f1 <- 1.0 / f1 = f2 + (int) j; / explicit: f1 < / f1 = f2 + j; / implicit: f1 < /..(s = a (int) + b (char) char > short > int > 0 double( double float( float(. 1 B type B LG U Q I B I I H I int x = ; short s; s = x; printf( d d\n, x, s); = 6 9 C T H 1 ( if (n = 0) { printf( something wrong ); 2 >

9 VT T I G U T I I G C I H I typedef typedef short int smallnumber; typedef unsigned char byte; typedef char String[100]; smallnumber x; byte b; String name; typedef char boolean; #define FALSE 0 #define TRUE 1 " ( check = x > 0; if (check == TRUE) { x ( " 2 ( I G U I G U 5 " typedef enum { Red, Orange, Yellow, Green, Blue, Violet Color; enum weather {rain, snow=2, sun=4; " " " ( B color + weather H " typedef enum { Red, Orange, Yellow Color; " #define Red 0 #define Orange 1 #define Yellow 2 typedef enum {False, True boolean; 51 8Q K H Q 4BE M 8Q E / / I H short int x; char ch; float pi = ; float f, g; I M N " " I " ( I A ( ) B 2 ch = a ; x = x + 4; ( scanf( df, x, f);

10 8Q 8Q 1 E 2 int foo(char x) { return x; pt = foo(x); pt = 17; ) " ( E 2 E 2 E E E E " E QQ I 8QQ I int x; int arr[20]; int main(int argc, char argv[]) { int i = 20; {into x; x = i + 7; int f(int n) { int a, p; a = 1; p = (int )malloc(sizeof int); malloc() " 3 ( free(). # " B char combine(char s, char t) { u = (char )malloc(strlen(s) + strlen(t) + 1); if (s = t) { strcpy(u, s); strcat(u, t); return u; else { return 0; GJ H H Q I " " ( 2 + (. 59 G H G U Header info Code Data - Heap Data - stack 5 3 / " 60 10

11 8Q I U I 8Q I U I, E(..(int x x int, type V < D int, E(..(int x 2 2 size_t( int - 1, < / /, 4 4 E, Eint xp x( xp x( int xp x 42 int int x Q I U I U I E( 4 E 4 E " E int a, b, c, d; d = 17; / BAD idea / a = 2; b = 3; c = a; d = b; if (c == d) puts( Same value ); c = 3; if (c == d) puts( Now same value ); c = d; if (c == d) puts ( Now same address ); ) " ( " I H Q I Q I I U I J ; {... if(switch for(while 6 X T X X J M...N " M N M N J " E "

12 4E I if 4E I if if (condition 1 ) {statements 1 else if (condition 2 ) {statements 2 else if (condition n-1 ) {statements n-1 else {statements n 2 M N ( if (x > 0) printf( x > 0 ); if (y > 0) printf( x and y > 0 ); E I switch 4E I switch switch(expression) { case const1: statements1; break; case const2: statements2; break; default: statementsn; 1 " Weather w; switch(w) { case rain: printf( bring umbrella ); case snow: printf( wear jacket ); break; case sun: printf( wear sunscreen ); break; default: printf( strange weather ); U I 4E I break M N M...N XX 2 ( 9 ( 9 2 ( 2 " for (init; condition; next) { statements1; if (condition2) break; statements2;

13 4E I continue Q T 8 Q continue " ( next for (init; condition1; next) { statement2; if (condition2) continue; statement2; if " E E array [] struct union ( G G int vec[100]; char str[30]; float m[10][10]; : + ( ( int x[10]; x[10] = 5; " " sizeof A sizeof A /sizeof A[0] 2 2 PrintArray(A, VECSIZE); struct ( ( E" #define VECSIZE G G O P 1 int i, sum = 0;... for (i = 0; i < VECSIZE; i++) sum += vec[i]; "..( " vec[-1] vec[10000] - H " ( Segmentation fault (core dumped) array J? O9 P int v, last; int sum = 0; last = vec[vecsize-1]; for (v = vec; v <= last; v++) sum += v;

14 V G G V T U H T int weekends[52][2]; [0][0] [0][1] [1][0] [1][1] [2][0] [2][1] [3][0].... weekends void main(void) { int number[12]; / 12 cells, one cell per student / int index, sum = 0; / Always initialize array before use / for (index = 0; index < 12; index++) { number[index] = index; / now, number[index]=index; will cause error:why?/ for (index = 0; index < 12; index = index + 1) { sum += number[index]; / sum array elements / return; weekends[2][1] (weekends+22+1) +, weekends B T O : H + 4 " # $ # ( ) ) B I I Q I I Q I U I ( (, (T (... X (4 X Q Q E<. 1 struct {int x; char y; float z; rec;... r.x = 3; r.y = a ; r.z= ; ; 1 struct complex {double real; double imag;; struct point {double x; double y; corner; typedef struct {double real; double imag; Complex; struct complex a, b; Complex c,d; a b 2 ( a c 2 (

15 Q Q V T U H 2 ( struct { char x; int y; char z; s1; sizeof(s1) =? struct { char x, z; int y; s2; sizeof(s2) =? struct person { char name[41]; int age; float height; struct { / embedded structure / int month; int day; int year; birth; ; struct person me; me.birth.year=1977; struct person class[60]; / array of info about everyone in class / class[0].name= Gun ; class[0].birth.year=1971; Q I Q I U I Q H I (..( typedef struct { unsigned int version:2; unsigned int p:1; unsigned int cc:4; unsigned int m:1; unsigned int pt:7; u_int16 seq; u_int32 ts; rtp_hdr_t; H +, - + H ". +, T H I I ( 2..( C (..( < B (x 0x8000) >> 31 3 " union u_tag { int ival; float fval; char sval; u;

16 U I I Q I V C EGJ I E C N int month[12]; / month is a pointer to base address 430/ month[3] = 7; / month address + 3 int elements => int at address (430+34) is now 7 / ptr = month + 2; / ptr points to month[2], => ptr is now (430+2 int elements)= 438 / ptr[5] = 12; / ptr address + 5 int elements => int at address (434+54) is now 12. Thus, month[7] is now 12 / ptr++; / ptr < size of int = 442 / (ptr + 4)[2] = 12; / accessing ptr[6] i.e., array[9] / + ( month[6], (month+6), (month+4)[2], ptr[3], (ptr+3). # 2 B Y Y $ $ ; $ $ I Q I I Q I. extern int putchar(int c); putchar( A ); int putchar(int c) { do something interesting here (, (. L. > static int x; static int times2(int c) { return c2; I Q I Q I I H. " / 0 ) ( 1 2 # 3 # / 0 ) ( 1. I Q I V extern char user2line [20]; / global variable defined in another file / char user1line[30]; / global for this file / void dummy(void); void main(void) { char user1line[20]; / different from earlier user1line[30] /... / restricted to this func / void dummy(){ extern char user1line[]; / the global user1line[30] /

17 @A BH I I Q I S H BH I I Q I $ $ - - H ( $ $ $ " L. > $ $ " $ $ 2 2 $ " $, 6 + H " (, BH I I Q I C EA H U H T.H 3 " #include mypgm.h void main(void) { myproc(); 7 #include mypgm.h void myproc(void) { mydata=2;... / some code / ) void myproc(void); int mydata; EW I IJ I J I Q I H ( 8 ( 1 ( : 5 - : " : : : : 7 8 " : Z 8 ( 1 ( : : : 7 8 int func(); /function returning integer/ int func(); /function returning pointer to integer/ int (func)(); /pointer to function returning integer/ int (func)(); /pointer to func returning ptr to int/

18 $ $ I Q IJU I $ ; < < 103 I J I Q IJV T U H void myproc (int d); void mycaller(void ( f)(int), int param); void main(void) { myproc(10); / call myproc with parameter 10/ mycaller(myproc, 10); / and do the same again / void mycaller(void ( f)(int), int param){ (f)(param); / call function f with param / void myproc (int d){... / do something with d / 104 B 4E E H G < -. : = - > > )? :,? 7 = :, 7 = E Q B I, D..(UHA 8 W (U$ HA 8 8 (... ( " - O 2 [ 9 7 P 7 O 2 [ P O 9 7 P O \ -] Q ^ _?...P O R R P O [ P O 2 P 107 ( E ( E ( 2 A F G A a c a t \0 F G R9 H

19 B I B I char makebig(char s) { s[0] = toupper(s[0]); return s; makebig( a cat ); char str = my string ; char s; s = str[0]; s = str; " R9 char str = my string ;... int i; for (i = 0; str[i] = \0 ; i++) putchar(str[i]); char s; for (s = str; s; s++) putchar(s); B I UG I B I " B 2 2 C D D B C " B C. s = t B s t ( X char mybuffer[100];... mybuffer = a cat ; " - ) strcpy(mybuffer, a cat ) T U H B I I U H I B I S E H G #include <string.h> int main(void) { char line[100]; char family, given, gap; printf( Enter your name: ); fgets(line,100,stdin); given = line; for (gap = line; gap; gap++) if (isspace(gap)) break; gap = \0 ; family = gap+1; printf( Your name: s, s\n, family, given); return 0; ( ) - + ) 3 - X + ) 3 X + )

20 B I S E H G B I ( + ) 3 X + ) 3 < = (V (W (... $ = (V (W ( B I B I,,, " " : B E C B I B I V T U H : I E X E nc nd n.mf ( ( ( 4 F = ; G 5 B 2 C B 2 C $ D D $ D n.mg n.ms ( ( H 4 5 I $

21 4E H G " FILE E FILE stdin( stdout( stderr H O H M 4E G UI K#M Q K : J K ) 1 FG (F G (FG (F/ G? : (+ ) 3 3 J K ) 1 : (1 : Q E JH X 1 L J J K ) 1 : 3 1 X 1 L J X 1 L J J K ) 1 X 1 L J $ J K ) 1 A 2 6 URH ( " (+ ) 3 3 B J K ) 1 2 A 1 : 123 G S J K ) 1 J K ) 1 ( J (( H 5 H H + B " # H ( ( (

Why learn C (after Java)? C for Java programmers. What does this C program do? Simple Example. Goals of this tutorial

Why learn C (after Java)? C for Java programmers. What does this C program do? Simple Example. Goals of this tutorial Why learn C (after Java)? C for Java programmers With Thanks to Indranil Gupta & Cornell Both high-level and low-level language Better control of low-level mechanisms Performance better than Java (Unix,

More information

High Performance Computing in C and C++

High Performance Computing in C and C++ High Performance Computing in C and C++ Rita Borgo Computer Science Department, Swansea University Summary Introduction to C Writing a simple C program Compiling a simple C program Running a simple C program

More information

CSC 322: Computer Organization Lab

CSC 322: Computer Organization Lab CSC 322: Computer Organization Lab Lecture 01: Introduction to C Course Introduction Lab will be held on Thursdays from 11:00-12:15 pm, from January 16, 2018 until April 25, 2018 Prerequisites The ability

More information

C for Java Programmers

C for Java Programmers C for Java Programmers Adapted from: Software Construction (J. Shepherd) Operating Systems at Cornell (Indranil Gupta) C history C Dennis Ritchie in late 1960s and early 1970s systems programming language

More information

Embedded Software TI2725 C. 2. C programming. Koen Langendoen

Embedded Software TI2725 C. 2. C programming. Koen Langendoen Embedded Software 2. C programming TI2725 C Koen Langendoen Embedded bdddsoftware Group C crash course For Java programmers Main differences Common pitfalls Language + tools // next lecture Learning by

More information

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef today advanced data types (1) typedef. mon 23 sep 2002 homework #1 due today homework #2 out today quiz #1 next class 30-45 minutes long one page of notes topics: C advanced data types dynamic memory allocation

More information

C for Java programmers. Carlo U. Nicola, FHNW SG I Loosely based on notes of I. Gupta Cornell University

C for Java programmers. Carlo U. Nicola, FHNW SG I Loosely based on notes of I. Gupta Cornell University C for Java programmers Carlo U. Nicola, FHNW SG I Loosely based on notes of I. Gupta Cornell University Why learn C (after Java)?! It is a middling language between machine code and human understandable

More information

CS3157: Advanced Programming. Announcement

CS3157: Advanced Programming. Announcement CS3157: Advanced Programming Lecture #10 Mar 20 Shlomo Hershkop shlomo@cs.columbia.edu Announcement Welcome back from spring break Hope you ve caught up with your courses Have the exams back, will return

More information

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3). cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion

More information

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch

More information

PRINCIPLES OF OPERATING SYSTEMS

PRINCIPLES OF OPERATING SYSTEMS PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)

More information

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Adapted from the slides Revisões sobre Programação em C, Sérgio Crisóstomo Compilation #include int main()

More information

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

More information

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso Why C? Test on 21 Android Devices with 32-bits and 64-bits processors and different versions

More information

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

More information

CS3157: Advanced Programming. Lecture #1 May 21 Shlomo Hershkop

CS3157: Advanced Programming. Lecture #1 May 21 Shlomo Hershkop CS3157: Advanced Programming Lecture #1 May 21 Shlomo Hershkop shlomo@cs.columbia.edu 1 Who am I Shlomo Hershkop About me Aim: Prof Hershkop My Research Actually also a unix command 2 It summer Session!

More information

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14 C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

More information

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types

More information

COMP 2355 Introduction to Systems Programming

COMP 2355 Introduction to Systems Programming COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Functions Similar to (static) methods in Java without the class: int f(int a, int

More information

Memory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)

Memory. 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 information

An Ungentle Introduction to C

An Ungentle Introduction to C Warum C? - Sicherheit auf allen Systemschichten Applikationen Hilfssysteme BS-Werkzeuge BS-Kern HW Evtl. Hochsprachen Skripte C Assembler - je tiefer die kompromittierte Schicht, umso größer der Schaden

More information

CS 61C: Great Ideas in Computer Architecture Introduction to C

CS 61C: Great Ideas in Computer Architecture Introduction to C CS 61C: Great Ideas in Computer Architecture Introduction to C Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/ 1 Agenda C vs. Java vs. Python Quick Start Introduction

More information

High Performance Computing Lecture 1. Matthew Jacob Indian Institute of Science

High Performance Computing Lecture 1. Matthew Jacob Indian Institute of Science High Performance Computing Lecture 1 Matthew Jacob Indian Institute of Science Agenda 1. Program execution: Compilation, Object files, Function call and return, Address space, Data & its representation

More information

Contents. A Review of C language. Visual C Visual C++ 6.0

Contents. A Review of C language. Visual C Visual C++ 6.0 A Review of C language C++ Object Oriented Programming Pei-yih Ting NTOU CS Modified from www.cse.cuhk.edu.hk/~csc2520/tuto/csc2520_tuto01.ppt 1 2 3 4 5 6 7 8 9 10 Double click 11 12 Compile a single source

More information

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut

mith 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 information

Final CSE 131B Spring 2005

Final CSE 131B Spring 2005 Login name Signature Name Student ID Final CSE 131B Spring 2005 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (27 points) (24 points) (32 points) (24 points) (32 points) (26 points) (31 points)

More information

Today s class. Finish computer system overview Review of more C. Informationsteknologi. Thursday, September 6, 2007

Today s class. Finish computer system overview Review of more C. Informationsteknologi. Thursday, September 6, 2007 Today s class Finish computer system overview Review of more C Computer Systems/Operating Systems - Class 2 1 Finish computer system overview Instruction Execution Two steps Processor reads (fetches) instructions

More information

Floating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions

Floating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions Announcements Thursday Extras: CS Commons on Thursdays @ 4:00 pm but none next week No office hours next week Monday or Tuesday Reflections: when to use if/switch statements for/while statements Floating-point

More information

High Performance Programming Programming in C part 1

High Performance Programming Programming in C part 1 High Performance Programming Programming in C part 1 Anastasia Kruchinina Uppsala University, Sweden April 18, 2017 HPP 1 / 53 C is designed on a way to provide a full control of the computer. C is the

More information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify

More information

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee. Midterm Exam Nov 8th, 2012 COMS W3157 Advanced Programming Columbia University Fall 2012 Instructor: Jae Woo Lee About this exam: - There are 4 problems totaling 100 points: problem 1: 30 points problem

More information

Introduction to C. Robert Escriva. Cornell CS 4411, August 30, Geared toward programmers

Introduction to C. Robert Escriva. Cornell CS 4411, August 30, Geared toward programmers Introduction to C Geared toward programmers Robert Escriva Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Cornell CS 4411, August 30, 2010 1 Why C? 2 A Quick Example 3 Programmer s Responsibilities

More information

Intermediate Programming, Spring 2017*

Intermediate Programming, Spring 2017* 600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

More information

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( )

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( ) Systems Group Department of Computer Science ETH Zürich Tutorial 1: Introduction to C Computer Architecture and Systems Programming (252-0061-00) Herbstsemester 2012 Goal Quick introduction to C Enough

More information

Final CSE 131B Spring 2004

Final CSE 131B Spring 2004 Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)

More information

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level

More information

Introduction to C. Sean Ogden. Cornell CS 4411, August 30, Geared toward programmers

Introduction to C. Sean Ogden. Cornell CS 4411, August 30, Geared toward programmers Introduction to C Geared toward programmers Sean Ogden Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Robert Escriva Zhiyuan Teo Ayush Dubey Cornell CS 4411, August 30, 2013 Administrative Information

More information

Intermediate Programming, Spring 2017*

Intermediate Programming, Spring 2017* 600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

More information

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam Multimedia Programming 2004 Lecture 2 Erwin M. Bakker Joachim Rijsdam Recap Learning C++ by example No groups: everybody should experience developing and programming in C++! Assignments will determine

More information

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

CSci 4061 Introduction to Operating Systems. Programs in C/Unix CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,

More information

do { write_program; OK = test_program ( ); } while (!OK); upload program to customer;

do { write_program; OK = test_program ( ); } while (!OK); upload program to customer; do { write_program; OK = test_program ( ); while (!OK); upload program to customer; /* Read text from stdin. Convert the first character of each "word" to uppercase, where a word is a sequence of letters.

More information

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems Deep C Multifile projects Getting it running Data types Typecasting Memory management Pointers Fabián E. Bustamante, Fall 2004 Multifile Projects Give your project a structure Modularized design Reuse

More information

Topic 6: A Quick Intro To C

Topic 6: A Quick Intro To C Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions

More information

Introduction to C. Ayush Dubey. Cornell CS 4411, August 31, Geared toward programmers

Introduction to C. Ayush Dubey. Cornell CS 4411, August 31, Geared toward programmers Introduction to C Geared toward programmers Ayush Dubey Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Robert Escriva Zhiyuan Teo Cornell CS 4411, August 31, 2012 Administrative Information Outline

More information

From 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 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 information

Procedures, Parameters, Values and Variables. Steven R. Bagley

Procedures, Parameters, Values and Variables. Steven R. Bagley Procedures, Parameters, Values and Variables Steven R. Bagley Recap A Program is a sequence of statements (instructions) Statements executed one-by-one in order Unless it is changed by the programmer e.g.

More information

ELEC 377 C Programming Tutorial. ELEC Operating Systems

ELEC 377 C Programming Tutorial. ELEC Operating Systems ELE 377 Programming Tutorial Outline! Short Introduction! History & Memory Model of! ommon Errors I have seen over the years! Work through a linked list example on the board! - uses everything I talk about

More information

CGS 3460 Summer 07 Midterm Exam

CGS 3460 Summer 07 Midterm Exam Short Answer 3 Points Each 1. What would the unix command gcc somefile.c -o someotherfile.exe do? 2. Name two basic data types in C. 3. A pointer data type holds what piece of information? 4. This key

More information

Dynamic memory allocation (malloc)

Dynamic memory allocation (malloc) 1 Plan for today Quick review of previous lecture Array of pointers Command line arguments Dynamic memory allocation (malloc) Structures (Ch 6) Input and Output (Ch 7) 1 Pointers K&R Ch 5 Basics: Declaration

More information

C 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. 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 information

Programming in C. What is C?... What is C?

Programming in C. What is C?... What is C? C Programming in C UVic SEng 265 Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier, in 1969, Ritchie and Thompson developed the Unix operating system We will be focusing on a version

More information

Agenda. Components of a Computer. Computer Memory Type Name Addr Value. Pointer Type. Pointers. CS 61C: Great Ideas in Computer Architecture

Agenda. Components of a Computer. Computer Memory Type Name Addr Value. Pointer Type. Pointers. CS 61C: Great Ideas in Computer Architecture CS 61C: Great Ideas in Computer Architecture Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c And in Conclusion, 2 Processor Control Datapath Components of a Computer PC Registers Arithmetic

More information

Programming in C UVic SEng 265

Programming in C UVic SEng 265 Programming in C UVic SEng 265 Daniel M. German Department of Computer Science University of Victoria 1 SEng 265 dmgerman@uvic.ca C Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier,

More information

Programming in C. What is C?... What is C?

Programming in C. What is C?... What is C? Programming in C UVic SEng 265 C Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier, in 1969, Ritchie and Thompson developed the Unix operating system We will be focusing on a version

More information

CSE 333 Midterm Exam Sample Solution 5/10/13

CSE 333 Midterm Exam Sample Solution 5/10/13 Question 1. (18 points) Consider these two C files: a.c void f(int p); int main() { f(17); return 0; b.c void f(char *p) { *p = 'x'; (a) Why is the program made from a.c and b.c incorrect? What would you

More information

mith College Computer Science CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut

mith College Computer Science CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut mith College CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 4 Hours! D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to

More information

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Krste Asanović & Randy Katz

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Krste Asanović & Randy Katz CS 61C: Great Ideas in Computer Architecture Lecture 3: Pointers Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Agenda Pointers in C Arrays in C This is not on the test Pointer arithmetic

More information

Organization of a file

Organization of a file File Handling 1 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example: Consider keeping students records 100 students

More information

CSE 5A Final Fall 2006

CSE 5A Final Fall 2006 Student ID cs5f Name Signature CSE 5A Final Fall 2006 Page 1 (18 points) Page 2 (26 points) Page 3 (28 points) Page 4 (16 points) Page 5 (40 points) Page 6 (44 points) Total (172 points = 164 points +

More information

Dynamic memory allocation

Dynamic 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 information

Outline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C

Outline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C Lecture 1 C primer What we will cover A crash course in the basics of C You should read the K&R C book for lots more details Various details will be exemplified later in the course Outline Overview comparison

More information

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems Programs CSCI 4061 Introduction to Operating Systems C Program Structure Libraries and header files Compiling and building programs Executing and debugging Instructor: Abhishek Chandra Assume familiarity

More information

CSE 333 Midterm Exam 5/10/13

CSE 333 Midterm Exam 5/10/13 Name There are 5 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed

More information

Friday, September 16, Lab Notes. Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week

Friday, 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 information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most

More information

Computational Methods of Scientific Programming Fall 2007

Computational Methods of Scientific Programming Fall 2007 MIT OpenCourseWare http://ocw.mit.edu 12.010 Computational Methods of Scientific Programming Fall 2007 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

More information

TELE402. Internetworking. TELE402 Lecture 1 Protocol Layering 1

TELE402. Internetworking. TELE402 Lecture 1 Protocol Layering 1 TELE402 Internetworking TELE402 Lecture 1 Protocol Layering 1 People Lecturer Dr. Zhiyi Huang Email: hzy@cs.otago.ac.nz Phone: 479-5680 Office: 1.26 Owheo Building Teaching Assistant Kai-Cheung Leung Email:

More information

COMP 2355 Introduction to Systems Programming

COMP 2355 Introduction to Systems Programming COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Pointers Pointers denote addresses in memory In C types, the * represents the use

More information

ECE 250 / CS 250 Computer Architecture. C Programming

ECE 250 / CS 250 Computer Architecture. C Programming ECE 250 / CS 250 Computer Architecture C Programming Benjamin Lee Some slides based on those from Alvin Lebeck, Daniel Sorin, Andrew Hilton, Amir Roth, Gershon Kedem Outline Previously: Computer is a machine

More information

Introduction to C. Systems Programming Concepts

Introduction to C. Systems Programming Concepts Introduction to C Systems Programming Concepts Introduction to C A simple C Program Variable Declarations printf ( ) Compiling and Running a C Program Sizeof Program #include What is True in C? if example

More information

C programming basics T3-1 -

C programming basics T3-1 - C programming basics T3-1 - Outline 1. Introduction 2. Basic concepts 3. Functions 4. Data types 5. Control structures 6. Arrays and pointers 7. File management T3-2 - 3.1: Introduction T3-3 - Review of

More information

Arrays and Pointers. CSE 2031 Fall November 11, 2013

Arrays 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 information

G52CPP C++ Programming Lecture 3. Dr Jason Atkin

G52CPP C++ Programming Lecture 3. Dr Jason Atkin G52CPP C++ Programming Lecture 3 Dr Jason Atkin E-Mail: jaa@cs.nott.ac.uk 1 Revision so far C/C++ designed for speed, Java for catching errors Java hides a lot of the details (so can C++) Much of C, C++

More information

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

COMP322 - Introduction to C++ Lecture 02 - Basics of C++ COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.

More information

ECE 250 / CPS 250 Computer Architecture. C Programming

ECE 250 / CPS 250 Computer Architecture. C Programming ECE 250 / CPS 250 Computer Architecture C Programming Benjamin Lee Slides based on those from Andrew Hilton (Duke), Alvy Lebeck (Duke) Benjamin Lee (Duke), and Amir Roth (Penn) Outline Previously:! Computer

More information

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.

More information

Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion

Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion CS 61C: Great Ideas in Computer Architecture Lecture 2: Numbers & C Language Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Numbers wrap-up This is not on the exam! Break C Primer Administrivia,

More information

BSM540 Basics of C Language

BSM540 Basics of C Language BSM540 Basics of C Language Chapter 4: Character strings & formatted I/O Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture To explain the input/output functions printf()

More information

unsigned char memory[] STACK ¼ 0x xC of address space globals function KERNEL code local variables

unsigned char memory[] STACK ¼ 0x xC of address space globals function KERNEL code local variables Graded assignment 0 will be handed out in section Assignment 1 Not that bad Check your work (run it through the compiler) Factorial Program Prints out ENTERING, LEAVING, and other pointers unsigned char

More information

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz CS 61C: Great Ideas in Computer Architecture Lecture 2: Numbers & C Language Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Numbers wrap-up This is not on the exam! Break C Primer Administrivia,

More information

Quick review of previous lecture Ch6 Structure Ch7 I/O. EECS2031 Software Tools. C - Structures, Unions, Enums & Typedef (K&R Ch.

Quick review of previous lecture Ch6 Structure Ch7 I/O. EECS2031 Software Tools. C - Structures, Unions, Enums & Typedef (K&R Ch. 1 Quick review of previous lecture Ch6 Structure Ch7 I/O EECS2031 Software Tools C - Structures, Unions, Enums & Typedef (K&R Ch.6) Structures Basics: Declaration and assignment Structures and functions

More information

In this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.

In this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8. In this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.Semantic www.tenouk.com, 1/16 C IDENTIFIERS 1. Is a unique

More information

CSCI-243 Exam 2 Review February 22, 2015 Presented by the RIT Computer Science Community

CSCI-243 Exam 2 Review February 22, 2015 Presented by the RIT Computer Science Community CSCI-43 Exam Review February, 01 Presented by the RIT Computer Science Community http://csc.cs.rit.edu C Preprocessor 1. Consider the following program: 1 # include 3 # ifdef WINDOWS 4 # include

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Friday, February 10, Lab Notes

Friday, 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 information

Arrays and Strings. Antonio Carzaniga. February 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga

Arrays and Strings. Antonio Carzaniga. February 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga Arrays and Strings Antonio Carzaniga Faculty of Informatics Università della Svizzera italiana February 23, 2015 Outline General memory model Definition and use of pointers Invalid pointers and common

More information

File IO and command line input CSE 2451

File IO and command line input CSE 2451 File IO and command line input CSE 2451 File functions Open/Close files fopen() open a stream for a file fclose() closes a stream One character at a time: fgetc() similar to getchar() fputc() similar to

More information

CSC231 C Tutorial Fall 2018 Introduction to C

CSC231 C Tutorial Fall 2018 Introduction to C mith College CSC231 C Tutorial Fall 2018 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 4 Installments! Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to Assembly Unix Standard

More information

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static

More information

Arrays and Pointers in C. Alan L. Cox

Arrays and Pointers in C. Alan L. Cox Arrays and Pointers in C Alan L. Cox alc@rice.edu Objectives Be able to use arrays, pointers, and strings in C programs Be able to explain the representation of these data types at the machine level, including

More information

ET156 Introduction to C Programming

ET156 Introduction to C Programming ET156 Introduction to C Programming Unit 1 INTRODUCTION TO C PROGRAMMING: THE C COMPILER, VARIABLES, MEMORY, INPUT, AND OUTPUT Instructor : Stan Kong Email : skong@itt tech.edutech.edu Figure 1.3 Components

More information

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Bernhard Boser & Randy Katz

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Bernhard Boser & Randy Katz CS 61C: Great Ideas in Computer Architecture Lecture 3: Pointers Bernhard Boser & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Agenda Pointers in C Arrays in C This is not on the test Pointer arithmetic

More information

EECS2031 Software Tools

EECS2031 Software Tools EECS2031 Software Tools SU 2014-2015 The Course EECS2031 Software Tools Lecture: R N203. Tuesdays 18:00 20:00 Labs: LAS (CSEB) 1006 Lab 01 Tuesdays 16:00 18: 00 Lab 02 Wednesdays 17:00 19:00 Course website:

More information

6.S096: Introduction to C/C++

6.S096: Introduction to C/C++ 6.S096: Introduction to C/C++ Frank Li, Tom Lieber, Kyle Murray Lecture 4: Data Structures and Debugging! January 17, 2012 Today Memory Leaks and Valgrind Tool Structs and Unions Opaque Types Enum and

More information

CS C Primer. Tyler Szepesi. January 16, 2013

CS C Primer. Tyler Szepesi. January 16, 2013 January 16, 2013 Topics 1 Why C? 2 Data Types 3 Memory 4 Files 5 Endianness 6 Resources Why C? C is exteremely flexible and gives control to the programmer Allows users to break rigid rules, which are

More information

Lecture 02 C FUNDAMENTALS

Lecture 02 C FUNDAMENTALS Lecture 02 C FUNDAMENTALS 1 Keywords C Fundamentals auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void

More information

2. Which of the following will print the value 2 for the above code?

2. Which of the following will print the value 2 for the above code? Computers are good at following instructions, but not at reading your mind. - Donald Knuth IMPORTANT QUESTIONS ON C LANGUAGE 1. What is the output of this program? char *ptr; char string[] = "How are you?";

More information

Common Misunderstandings from Exam 1 Material

Common Misunderstandings from Exam 1 Material Common Misunderstandings from Exam 1 Material Kyle Dewey Stack and Heap Allocation with Pointers char c = c ; char* p1 = malloc(sizeof(char)); char** p2 = &p1; Where is c allocated? Where is p1 itself

More information