SlideShare uma empresa Scribd logo
1 de 51
Brief Introduction to the C Programming Language Fred Kuhns [email_address] Applied Research Laboratory, Department of Computer Science and Engineering, Washington University in St. Louis
Introduction ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Standard C ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Elements of a C Program ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A Simple C Program ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],/*  you generally want to * include stdio.h and * stdlib.h *  */ #include <stdio.h> #include <stdlib.h> int main (void) { printf (“Hello World  ”); exit(0); }
Source and Header files ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Another Example C Program example.c /*  this is a C-style comment  * You generally want to palce * all file includes at start of file *  */ #include <stdio.h> #include <stdlib.h> int main (int argc, char **argv) { // this is a C++-style comment // printf prototype in stdio.h printf(“Hello, Prog name = %s”, argv[0]); exit(0); } /*  comments  */ #ifndef _STDIO_H #define _STDIO_H ... definitions and protoypes #endif /usr/include/stdio.h /*  prevents including file * contents multiple * times  */ #ifndef _STDLIB_H #define _STDLIB_H ... definitions and protoypes #endif /usr/include/stdlib.h #include  directs the preprocessor to “include” the contents of the file at this point in the source file. #define   directs preprocessor to define macros.
Passing Command Line Arguments ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],./try –g 2 fred argc  = 4, argv  =  <address0> ‘ t’‘r’‘y’‘’ argv : [0]  <addres1> [1]  <addres2> [2]   <addres3> [3]   <addres4> [4]  NULL ‘ -’‘g’‘’ ‘ 2’‘’ ‘ f’‘r’‘e’‘d’‘’
C Standard Header Files you may want to use ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Preprocessor ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Preprocessor: Macros ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Preprocessor: Conditional Compilation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Another Simple C Program ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Arrays and Pointers 0 1 2 3 4 1 0 2 3 little endian byte ordering memory layout for array x
Pointers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Pointers in C (and C++) Address 0x3dc 0x3d8 Program Memory 0x3cc 0x3c8 0x3c4 0x3c0 Note: The compiler converts z[1] or *(z+1) to Value at address  ( Address of z   +  sizeof(int)) ; In C you would write the byte address as: (char *)z + sizeof(int); or letting the compiler do the work for you (int *)z + 1; Step 1 : int main (int argc, argv) { int  x  = 4; int * y  = & x ; int * z [4] = { NULL ,  NULL ,  NULL ,  NULL }; int  a [4] = {1, 2, 3, 4}; ... 0x3bc 0x3b8 0x3b4 0x3b0 0x3d4 0x3d0 z[3] z[2] z[1] z[0] a[3] a[2] a[1] a[0] x y 4 0x3dc 0 0 0 0 4 3 2 1 NA NA
Pointers Continued 4 0x3dc Address 0x3dc 0x3d8 Program Memory 0x3bc 0x3b8 0x3b4 0x3b0 0x3cc 0x3c8 0x3c4 0x3c0 Step 1: int main (int argc, argv) { int  x = 4; int *y = &x; int *z[4] = {NULL, NULL, NULL, NULL}; int  a[4] = {1, 2, 3, 4}; Step 2 : Assign addresses to array Z z [0] =  a;   // same as & a [0] ; z [1] =  a + 1;   // same as &a[1] ; z [2] = a + 2; // same as &a[2]; z [3] = a + 3; // same as &a[3]; 0x3bc 0x3b8 0x3b4 0x3b0 4 3 2 1 NA 0x3d4 0x3d0 z[3] z[2] z[1] z[0] a[3] a[2] a[1] a[0] NA x y
Pointers Continued 4 0x3dc Address 0x3dc 0x3d8 Program Memory 0x3bc 0x3b8 0x3b4 0x3b0 0x3cc 0x3c8 0x3c4 0x3c0 Step 1: int main (int argc, argv) { int x = 4; int *y = &x; int *z[4] = {NULL, NULL, NULL, NULL}; int a[4] = {1, 2, 3, 4}; Step 2: z [0] = a; z [1] = a + 1; z [2] = a + 2; z [3] = a + 3; Step 3 : No change in z’s values z[0] = (int *)((char *)a); z[1] = (int *)((char *)a  + sizeof(int)); z[2] = (int *)((char *)a + 2 * sizeof(int)); z[3] = (int *)((char *)a + 3 * sizeof(int)); 0x3bc 0x3b8 0x3b4 0x3b0 4 3 2 1 NA 0x3d4 0x3d0 z[3] z[2] z[1] z[0] a[3] a[2] a[1] a[0] NA x y
Getting Fancy with Macros ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],# define   QINSERT_BEFORE (loc, node, field) do { *(loc)->field.prev = (node); (node)->field.prev = (loc)->field.prev; (loc)->field.prev  =  &((node)->field.next); (node)->field.next = (loc); } while (/* */0) # define   QINSERT_AFTER (loc, node, field) do { ((loc)->field.next)->field.prev =  &(node)->field.next; (node)->field.next = (loc)->field.next; (loc)->field.next = (node);  (node)->field.prev = &(loc)->field.next; } while ( /* */ 0) # define   QREMOVE (node, field) do { *((node)->field.prev) = (node)->field.next; ((node)->field.next)->field.prev = (node)->field.prev; (node)->field.next = (node); (node)->field.prev = &((node)->field.next); } while ( /* */ 0)
After Preprocessing and Compiling typedef struct wth_t { int state; QNODE(wth_t) alist; } wth_t; # define  QNODE (type) struct { struct type *next; struct type **prev; } typedef struct wth_t { int state; struct { struct wth_t *next; struct wth_t **prev; } alist; } wth_t; < integer >  state < address > next < address > prev 3 words in memory # define   QNODE_INIT (node, field) do {   (node)->field.next = (node);  (node)->field.prev = &(node)->field.next;} while ( /* */ 0 ); 0 0x00100 0x00104 0x100 head : instance of wth_t 0x104 0x108 memory layout after GCC CPP QNODE_INIT(head, alist)
QNODE Manipulations # define   QINSERT_BEFORE ( head ,  node ,  alist )do { *( head )-> alist .prev = ( node );  ( node )-> alist .prev = ( head )-> alist .prev;  ( head )-> alist .prev  = &( node )-> alist. next;( node )-> alist .next = ( head ); } while (/* */0) QINSERT_BEFORE(head, node0, alist); ? before 0x100 0 0x100 0x104 head  0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0  0x1a4 0x1a8
QNODE Manipulations # define   QINSERT_BEFORE ( head ,  node ,  alist )do { *( head )-> alist .prev = ( node );  (node)->alist.prev = (head)->alist.prev;  (head)->alist.prev  = &(node)->alist.next;(node)->alist.next = (head); } while (/* */0) QINSERT_BEFORE(head, node0, alist); before 0x100 0 0x100 0x104 head  0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0  0x1a4 0x1a8 0x100 0 0x1a0 0x104 head   0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0   0x1a4 0x1a8
QNODE Manipulations # define   QINSERT_BEFORE ( head ,  node ,  alist )do { *( head )-> alist .prev = ( node );  ( node )-> alist .prev = ( head )-> alist .prev;  ( head )-> alist .prev  = &( node )-> alist. next;( node )-> alist .next = ( head ); } while (/* */0) QINSERT_BEFORE(head, node0, alist); before 0x100 0 0x100 0x104 head  0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0  0x1a4 0x1a8 0x100 0 0x1a0 0x104 head   0x104 0x108 0x1a0 0 0x1a0 0x104 node0   0x1a4 0x1a8
QNODE Manipulations # define   QINSERT_BEFORE ( head ,  node ,  alist )do { *( head )-> alist .prev = ( node );  ( node )-> alist .prev = ( head )-> alist .prev;  ( head )-> alist .prev  = &( node )-> alist. next;( node )-> alist .next = ( head ); } while (/* */0) QINSERT_BEFORE(head, node0, alist); before 0x100 0 0x100 0x104 head  0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0  0x1a4 0x1a8 0x100 0 0x1a0 0x1a4 head   0x104 0x108 0x1a0 0 0x1a0 0x104 node0   0x1a4 0x1a8
QNODE Manipulations # define   QINSERT_BEFORE ( head ,  node ,  alist )do { *( head )-> alist .prev = ( node );  ( node )-> alist .prev = ( head )-> alist .prev;  ( head )-> alist .prev  = &( node )-> alist. next;( node )-> alist .next = ( head ); } while (/* */0) QINSERT_BEFORE(head, node0, alist); before 0x100 0 0x100 0x104 head  0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0  0x1a4 0x1a8 0x100 0 0x1a0 0x1a4 head   0x104 0x108 0x1a0 0 0x100 0x104 node0   0x1a4 0x1a8
QNODE Manipulations # define   QINSERT_BEFORE ( head ,  node ,  alist )do { *( head )-> alist .prev = ( node );  ( node )-> alist .prev = ( head )-> alist .prev;  ( head )-> alist .prev  = &( node )-> alist. next;( node )-> alist .next = ( head ); } while (/* */0) QINSERT_BEFORE(head, node0, alist); before 0x100 0 0x100 0x104 head  0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0  0x1a4 0x1a8 0x100 0 0x1a0 0x1a4 head   0x104 0x108 0x1a0 0 0x100 0x104 node0   0x1a4 0x1a8
Adding a Third Node QINSERT_BEFORE(head, node1, alist); # define   QINSERT_BEFORE ( head ,  node ,  alist )do { *( head )-> alist .prev = ( node );    ( node )-> alist .prev = ( head )-> alist .prev;    ( head )-> alist .prev  = &( node )-> alist. next;   ( node )-> alist .next = ( head ); } while (/* */0) 0x100 0 0x1a0 0x1a4 head  0x104 0x108 0x1a0 0 0x100 0x104 node0  0x1a4 0x1a8 0x200 0 0x200 0x204 node1 0x204 0x208 0x200 0 0x200 0x204 node1 0x204 0x208 0x100 0 0x1a0 0x1a4 head   0x104 0x108 0x1a0 0 0x100 0x104 node0   0x1a4 0x1a8
Adding a Third Node QINSERT_BEFORE(head, node1, alist); # define   QINSERT_BEFORE ( head ,  node1 ,  alist )do { *( head )-> alist .prev = ( node1 );    ( node1 )-> alist .prev = ( head )-> alist .prev;    ( head )-> alist .prev  = &( node1 )-> alist. next;   ( node1 )-> alist .next = ( head ); } while (/* */0) (1) (1) 0x100 0 0x1a0 0x1a4 head  0x104 0x108 0x1a0 0 0x100 0x104 node0  0x1a4 0x1a8 0x100 0 0x1a0 0x1a4 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x200 0x204 node1 0x204 0x208 0x200 0 0x200 0x204 node1 0x204 0x208
Adding a Third Node QINSERT_BEFORE(head, node1, alist); # define   QINSERT_BEFORE ( head ,  node1 ,  alist )do { *( head )-> alist .prev = ( node1 );    ( node1 )-> alist .prev = ( head )-> alist .prev;    ( head )-> alist .prev  = &( node1 )-> alist. next;   ( node1 )-> alist .next = ( head ); } while (/* */0) (1) (2) (2) 0x100 0 0x1a0 0x1a4 head  0x104 0x108 0x1a0 0 0x100 0x104 node0  0x1a4 0x1a8 0x100 0 0x1a0 0x1a4 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x200 0x204 node1 0x204 0x208 0x200 0 0x200 0x1a4 node1 0x204 0x208
Adding a Third Node QINSERT_BEFORE(head, node1, alist); # define   QINSERT_BEFORE ( head ,  node1 ,  alist )do { *( head )-> alist .prev = ( node1 );    ( node1 )-> alist .prev = ( head )-> alist .prev;    ( head )-> alist .prev  = &( node1 )-> alist. next;   ( node1 )-> alist .next = ( head ); } while (/* */0) (3) (3) 0x100 0 0x1a0 0x1a4 head  0x104 0x108 0x1a0 0 0x100 0x104 node0  0x1a4 0x1a8 0x100 0 0x1a0 0x204 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x200 0x204 node1 0x204 0x208 0x200 0 0x200 0x1a4 node1 0x204 0x208 (1) (1) (2) (2)
Adding a Third Node QINSERT_BEFORE(head, node1, alist); # define   QINSERT_BEFORE ( head ,  node1 ,  alist )do { *( head )-> alist .prev = ( node1 );    ( node1 )-> alist .prev = ( head )-> alist .prev;    ( head )-> alist .prev  = &( node1 )-> alist. next;   ( node1 )-> alist .next = ( head ); } while (/* */0) (1) (1) (2) (2) (3) (3) (4) (4) 0x100 0 0x1a0 0x1a4 head  0x104 0x108 0x1a0 0 0x100 0x104 node0  0x1a4 0x1a8 0x100 0 0x1a0 0x204 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x200 0x204 node1 0x204 0x208 0x200 0 0x100 0x1a4 node1 0x204 0x208
Removing a Node QREMOVE(node0, alist); # define   QREMOVE ( node ,  alist ) do { (1) *(( node )-> alist .prev) = ( node )-> alist .next; (2) (( node )-> alist .next)-> alist .prev = ( node )-> alist .prev;(3) ( node )-> alist .next = ( node ); (4) ( node )-> alist .prev = &(( node )-> alist .next); } while ( /* */ 0) 0x100 0 0x1a0 0x204 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208 0x100 0 ?? ?? head  0x104 0x108 0x1a0 0 ?? ?? node0  0x1a4 0x1a8 0x200 0 ?? ?? node1 0x204 0x208
Removing a Node QREMOVE(node0, alist); # define   QREMOVE ( node ,  alist ) do { *(( node )-> alist .prev) = ( node )-> alist .next;   (( node )-> alist .next)-> alist .prev = ( node )-> alist .prev;  ( node )-> alist .next = ( node );   ( node )-> alist .prev = &(( node )-> alist .next); } while ( /* */ 0) 0x100 0 0x1a0 0x204 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208 0x100 0 0x1a0 0x204 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208
Removing a Node QREMOVE(node0, alist); # define   QREMOVE ( node0 ,  alist ) do { (1) *(( node0 )->alist.prev) = ( node0 )->alist.next;   (( node0 )->alist.next)->alist.prev = ( node0 )->alist.prev;  ( node0 )->alist.next = ( node0 );   ( node0 )->alist.prev = &(( node0 )->alist.next); } while ( /* */ 0) (1) 0x100 0 0x200 0x204 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208 0x100 0 0x1a0 0x204 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208
Removing a Node QREMOVE(node0, alist); # define   QREMOVE ( node0 ,  alist ) do { *(( node0 )->alist.prev) = ( node0 )->alist.next; (2)  (( node0 )->alist.next)->alist.prev = ( node0 )->alist.prev;( node0 )->alist.next = ( node0 ); ( node0 )->alist.prev = &(( node0 )->alist.next); } while ( /* */ 0) (2) 0x100 0 0x200 0x204 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x100 0x104 node1 0x204 0x208 0x100 0 0x1a0 0x204 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208
Removing a Node QREMOVE(node0, alist); # define   QREMOVE ( node0 ,  alist ) do { *(( node0 )->alist.prev) = ( node0 )->alist.next;   (( node0 )->alist.next)->alist.prev = ( node0 )->alist.prev;(3)  ( node0 )->alist.next = ( node0 ); ( node0 )->alist.prev = &(( node0 )->alist.next); } while ( /* */ 0) (3) 0x100 0 0x200 0x204 head  0x104 0x108 0x1a0 0 0x1a0 0x104 node0  0x1a4 0x1a8 0x200 0 0x100 0x104 node1 0x204 0x208 0x100 0 0x1a0 0x204 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208
Removing a Node QREMOVE(node0, alist); # define   QREMOVE ( node0 ,  alist ) do { *(( node0 )->alist.prev) = ( node0 )->alist.next;   (( node0 )->alist.next)->alist.prev = ( node0 )->alist.prev;( node0 )->alist.next = ( node0 );   (4)  ( node0 )->alist.prev = &(( node0 )->alist.next); } while ( /* */ 0) (4) 0x100 0 0x200 0x204 head  0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0  0x1a4 0x1a8 0x200 0 0x100 0x104 node1 0x204 0x208 0x100 0 0x1a0 0x204 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208
Solution to Removing a Node QREMOVE(node0, alist); # define   QREMOVE ( node ,  alist ) do { (1) *(( node )-> alist .prev) = ( node )-> alist .next; (2) (( node )-> alist .next)-> alist .prev = ( node )-> alist .prev;(3) ( node )-> alist .next = ( node ); (4) ( node )-> alist .prev = &(( node )-> alist .next); } while ( /* */ 0) 0x100 0 0x1a0 0x204 head  0x104 0x108 0x1a0 0 0x200 0x104 node0  0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208 0x100 0 0x200 0x204 head  0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0  0x1a4 0x1a8 0x200 0 0x100 0x104 node1 0x204 0x208
Functions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Basic Types and Operators ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Operator Precedence  (from “C a Reference Manual”, 5 th  Edition) 15 16 Precedence right-to-left unary address of & right-to-left unary indirection ( dereference ) * right-to-left unary negation, plus - + right-to-left unary logical not ! right-to-left unary bitwise not ~ right-to-left prefix increment, decrement ++  -- left-to-right postfix compound literal ( type ){ init } left-to-right postfix increment, decrement ++ -- left-to-right postfix direct selection . left-to-right postfix function call f (...) left-to-right postfix subscripting a [k] size indirect selection simple tokens Operator n/a primary names, literals right-to-left unary sizeof left to right postfix -> Associates Class Tokens 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Precedence right-to-left unary casts ( type ) left-to-right binary multiplicative * / %  left-to-right binary additive + - sequential eval. assignment conditional logical or logical and bitwise or bitwise xor bitwise and equality/ineq. relational left, right shift Operator left-to-right binary , right-to-left binary = += -= *= /= %= &= ^= |= <<= >>= right-to-left ternary ?: left-to-right binary || left-to-right binary && left-to-right binary | left-to-right binary ^ left-to-right binary & left-to-right binary == != left-to-right binary < <= > >= left-to-right binary << >> Associates Class Tokens
Structs and Unions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Conditional Statements (if/else) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Conditional Statements (switch) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Loops ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Building your program ,[object Object],[object Object],[object Object],[object Object],[object Object]
make and Makefiles, Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Makefiles ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example Makefile for wulib ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],# Makefile.inc # Contains common definitions MyOS := $(shell uname -s) MyID := $(shell whoami) MyHost := $(shell hostname) WARNSTRICT := -W   -Wstrict-prototypes -Wmissing-prototypes WARNLIGHT := -Wall WARN := ${WARNLIGHT} ALLFLGS := -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE APPCFLGS = $(ALLFLGS) $(WARN) WUCC := gcc WUCFLAGS := -DMyOS=$(MyOS) $(OSFLAGS) $(ALLFLGS) $(WARN) WUINCLUDES := WULIBS := -lm ifeq (${MyOS), SunOS) OSLIBS+= -lrt endif Makefile.inc Makefile
Project Documentation ,[object Object],[object Object],[object Object],[object Object],[object Object]
Attacking a Project ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Mais conteúdo relacionado

Mais procurados

C++ Advanced
C++ AdvancedC++ Advanced
C++ AdvancedVivek Das
 
Objective c beginner's guide
Objective c beginner's guideObjective c beginner's guide
Objective c beginner's guideTiago Faller
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - englishJen Yee Hong
 
Extending Python - EuroPython 2014
Extending Python - EuroPython 2014Extending Python - EuroPython 2014
Extending Python - EuroPython 2014fcofdezc
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpen Gurukul
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstackThierry Gayet
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesEelco Visser
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with StatixEelco Visser
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Chris Adamson
 
Paradigmas de Linguagens de Programacao - Aula #5
Paradigmas de Linguagens de Programacao - Aula #5Paradigmas de Linguagens de Programacao - Aula #5
Paradigmas de Linguagens de Programacao - Aula #5Ismar Silveira
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)Saifur Rahman
 

Mais procurados (19)

College1
College1College1
College1
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 
Objective c beginner's guide
Objective c beginner's guideObjective c beginner's guide
Objective c beginner's guide
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
 
Extending Python - EuroPython 2014
Extending Python - EuroPython 2014Extending Python - EuroPython 2014
Extending Python - EuroPython 2014
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ Programming
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstack
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
Paradigmas de Linguagens de Programacao - Aula #5
Paradigmas de Linguagens de Programacao - Aula #5Paradigmas de Linguagens de Programacao - Aula #5
Paradigmas de Linguagens de Programacao - Aula #5
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
C++ theory
C++ theoryC++ theory
C++ theory
 
C++ via C#
C++ via C#C++ via C#
C++ via C#
 
Oop Presentation
Oop PresentationOop Presentation
Oop Presentation
 

Destaque

SCORE social media_workshop(08202011)v2
SCORE social media_workshop(08202011)v2SCORE social media_workshop(08202011)v2
SCORE social media_workshop(08202011)v2Ralph J. Davila, APR
 
Smacking
SmackingSmacking
SmackingESOL
 
2011 S2S Course Maps - PDF
2011 S2S Course Maps - PDF2011 S2S Course Maps - PDF
2011 S2S Course Maps - PDFmatthewringer
 
2010 Sunset to Sunrise Relay Leg Maps
2010 Sunset to Sunrise Relay Leg Maps2010 Sunset to Sunrise Relay Leg Maps
2010 Sunset to Sunrise Relay Leg Mapsmatthewringer
 
采购指南Q4 w3
采购指南Q4 w3采购指南Q4 w3
采购指南Q4 w3stalingrad
 
Survival of the Fittest: The Biggest "Game" Will Win (Gamification)
Survival of the Fittest: The Biggest "Game" Will Win (Gamification)Survival of the Fittest: The Biggest "Game" Will Win (Gamification)
Survival of the Fittest: The Biggest "Game" Will Win (Gamification)Ralph J. Davila, APR
 
Costume Drama on TV and Film
Costume Drama on TV and FilmCostume Drama on TV and Film
Costume Drama on TV and FilmESOL
 

Destaque (9)

Demotest
DemotestDemotest
Demotest
 
SCORE social media_workshop(08202011)v2
SCORE social media_workshop(08202011)v2SCORE social media_workshop(08202011)v2
SCORE social media_workshop(08202011)v2
 
Smacking
SmackingSmacking
Smacking
 
2011 S2S Course Maps - PDF
2011 S2S Course Maps - PDF2011 S2S Course Maps - PDF
2011 S2S Course Maps - PDF
 
Demotest
DemotestDemotest
Demotest
 
2010 Sunset to Sunrise Relay Leg Maps
2010 Sunset to Sunrise Relay Leg Maps2010 Sunset to Sunrise Relay Leg Maps
2010 Sunset to Sunrise Relay Leg Maps
 
采购指南Q4 w3
采购指南Q4 w3采购指南Q4 w3
采购指南Q4 w3
 
Survival of the Fittest: The Biggest "Game" Will Win (Gamification)
Survival of the Fittest: The Biggest "Game" Will Win (Gamification)Survival of the Fittest: The Biggest "Game" Will Win (Gamification)
Survival of the Fittest: The Biggest "Game" Will Win (Gamification)
 
Costume Drama on TV and Film
Costume Drama on TV and FilmCostume Drama on TV and Film
Costume Drama on TV and Film
 

Semelhante a Csdfsadf

Brief introduction to the c programming language
Brief introduction to the c programming languageBrief introduction to the c programming language
Brief introduction to the c programming languageKumar Gaurav
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupSyedHaroonShah4
 
C Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer CentreC Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer Centrejatin batra
 
88 c programs 15184
88 c programs 1518488 c programs 15184
88 c programs 15184Sumit Saini
 
Getting Started Cpp
Getting Started CppGetting Started Cpp
Getting Started CppLong Cao
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++oggyrao
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.pptUdhayaKumar175069
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in Cummeafruz
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functionsray143eddie
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.pptAlefya1
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingAlpana Gupta
 

Semelhante a Csdfsadf (20)

Brief introduction to the c programming language
Brief introduction to the c programming languageBrief introduction to the c programming language
Brief introduction to the c programming language
 
C.ppt
C.pptC.ppt
C.ppt
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
 
C Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer CentreC Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer Centre
 
88 c programs 15184
88 c programs 1518488 c programs 15184
88 c programs 15184
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
Getting Started Cpp
Getting Started CppGetting Started Cpp
Getting Started Cpp
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
 
C tutorial
C tutorialC tutorial
C tutorial
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
C tutorial
C tutorialC tutorial
C tutorial
 
Structures-2
Structures-2Structures-2
Structures-2
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in C
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 

Último

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Último (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Csdfsadf

  • 1. Brief Introduction to the C Programming Language Fred Kuhns [email_address] Applied Research Laboratory, Department of Computer Science and Engineering, Washington University in St. Louis
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. Another Example C Program example.c /* this is a C-style comment * You generally want to palce * all file includes at start of file * */ #include <stdio.h> #include <stdlib.h> int main (int argc, char **argv) { // this is a C++-style comment // printf prototype in stdio.h printf(“Hello, Prog name = %s”, argv[0]); exit(0); } /* comments */ #ifndef _STDIO_H #define _STDIO_H ... definitions and protoypes #endif /usr/include/stdio.h /* prevents including file * contents multiple * times */ #ifndef _STDLIB_H #define _STDLIB_H ... definitions and protoypes #endif /usr/include/stdlib.h #include directs the preprocessor to “include” the contents of the file at this point in the source file. #define directs preprocessor to define macros.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. Pointers in C (and C++) Address 0x3dc 0x3d8 Program Memory 0x3cc 0x3c8 0x3c4 0x3c0 Note: The compiler converts z[1] or *(z+1) to Value at address ( Address of z + sizeof(int)) ; In C you would write the byte address as: (char *)z + sizeof(int); or letting the compiler do the work for you (int *)z + 1; Step 1 : int main (int argc, argv) { int x = 4; int * y = & x ; int * z [4] = { NULL , NULL , NULL , NULL }; int a [4] = {1, 2, 3, 4}; ... 0x3bc 0x3b8 0x3b4 0x3b0 0x3d4 0x3d0 z[3] z[2] z[1] z[0] a[3] a[2] a[1] a[0] x y 4 0x3dc 0 0 0 0 4 3 2 1 NA NA
  • 17. Pointers Continued 4 0x3dc Address 0x3dc 0x3d8 Program Memory 0x3bc 0x3b8 0x3b4 0x3b0 0x3cc 0x3c8 0x3c4 0x3c0 Step 1: int main (int argc, argv) { int x = 4; int *y = &x; int *z[4] = {NULL, NULL, NULL, NULL}; int a[4] = {1, 2, 3, 4}; Step 2 : Assign addresses to array Z z [0] = a; // same as & a [0] ; z [1] = a + 1; // same as &a[1] ; z [2] = a + 2; // same as &a[2]; z [3] = a + 3; // same as &a[3]; 0x3bc 0x3b8 0x3b4 0x3b0 4 3 2 1 NA 0x3d4 0x3d0 z[3] z[2] z[1] z[0] a[3] a[2] a[1] a[0] NA x y
  • 18. Pointers Continued 4 0x3dc Address 0x3dc 0x3d8 Program Memory 0x3bc 0x3b8 0x3b4 0x3b0 0x3cc 0x3c8 0x3c4 0x3c0 Step 1: int main (int argc, argv) { int x = 4; int *y = &x; int *z[4] = {NULL, NULL, NULL, NULL}; int a[4] = {1, 2, 3, 4}; Step 2: z [0] = a; z [1] = a + 1; z [2] = a + 2; z [3] = a + 3; Step 3 : No change in z’s values z[0] = (int *)((char *)a); z[1] = (int *)((char *)a + sizeof(int)); z[2] = (int *)((char *)a + 2 * sizeof(int)); z[3] = (int *)((char *)a + 3 * sizeof(int)); 0x3bc 0x3b8 0x3b4 0x3b0 4 3 2 1 NA 0x3d4 0x3d0 z[3] z[2] z[1] z[0] a[3] a[2] a[1] a[0] NA x y
  • 19.
  • 20. After Preprocessing and Compiling typedef struct wth_t { int state; QNODE(wth_t) alist; } wth_t; # define QNODE (type) struct { struct type *next; struct type **prev; } typedef struct wth_t { int state; struct { struct wth_t *next; struct wth_t **prev; } alist; } wth_t; < integer > state < address > next < address > prev 3 words in memory # define QNODE_INIT (node, field) do { (node)->field.next = (node); (node)->field.prev = &(node)->field.next;} while ( /* */ 0 ); 0 0x00100 0x00104 0x100 head : instance of wth_t 0x104 0x108 memory layout after GCC CPP QNODE_INIT(head, alist)
  • 21. QNODE Manipulations # define QINSERT_BEFORE ( head , node , alist )do { *( head )-> alist .prev = ( node ); ( node )-> alist .prev = ( head )-> alist .prev; ( head )-> alist .prev = &( node )-> alist. next;( node )-> alist .next = ( head ); } while (/* */0) QINSERT_BEFORE(head, node0, alist); ? before 0x100 0 0x100 0x104 head 0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0 0x1a4 0x1a8
  • 22. QNODE Manipulations # define QINSERT_BEFORE ( head , node , alist )do { *( head )-> alist .prev = ( node ); (node)->alist.prev = (head)->alist.prev; (head)->alist.prev = &(node)->alist.next;(node)->alist.next = (head); } while (/* */0) QINSERT_BEFORE(head, node0, alist); before 0x100 0 0x100 0x104 head 0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0 0x1a4 0x1a8 0x100 0 0x1a0 0x104 head 0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0 0x1a4 0x1a8
  • 23. QNODE Manipulations # define QINSERT_BEFORE ( head , node , alist )do { *( head )-> alist .prev = ( node ); ( node )-> alist .prev = ( head )-> alist .prev; ( head )-> alist .prev = &( node )-> alist. next;( node )-> alist .next = ( head ); } while (/* */0) QINSERT_BEFORE(head, node0, alist); before 0x100 0 0x100 0x104 head 0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0 0x1a4 0x1a8 0x100 0 0x1a0 0x104 head 0x104 0x108 0x1a0 0 0x1a0 0x104 node0 0x1a4 0x1a8
  • 24. QNODE Manipulations # define QINSERT_BEFORE ( head , node , alist )do { *( head )-> alist .prev = ( node ); ( node )-> alist .prev = ( head )-> alist .prev; ( head )-> alist .prev = &( node )-> alist. next;( node )-> alist .next = ( head ); } while (/* */0) QINSERT_BEFORE(head, node0, alist); before 0x100 0 0x100 0x104 head 0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0 0x1a4 0x1a8 0x100 0 0x1a0 0x1a4 head 0x104 0x108 0x1a0 0 0x1a0 0x104 node0 0x1a4 0x1a8
  • 25. QNODE Manipulations # define QINSERT_BEFORE ( head , node , alist )do { *( head )-> alist .prev = ( node ); ( node )-> alist .prev = ( head )-> alist .prev; ( head )-> alist .prev = &( node )-> alist. next;( node )-> alist .next = ( head ); } while (/* */0) QINSERT_BEFORE(head, node0, alist); before 0x100 0 0x100 0x104 head 0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0 0x1a4 0x1a8 0x100 0 0x1a0 0x1a4 head 0x104 0x108 0x1a0 0 0x100 0x104 node0 0x1a4 0x1a8
  • 26. QNODE Manipulations # define QINSERT_BEFORE ( head , node , alist )do { *( head )-> alist .prev = ( node ); ( node )-> alist .prev = ( head )-> alist .prev; ( head )-> alist .prev = &( node )-> alist. next;( node )-> alist .next = ( head ); } while (/* */0) QINSERT_BEFORE(head, node0, alist); before 0x100 0 0x100 0x104 head 0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0 0x1a4 0x1a8 0x100 0 0x1a0 0x1a4 head 0x104 0x108 0x1a0 0 0x100 0x104 node0 0x1a4 0x1a8
  • 27. Adding a Third Node QINSERT_BEFORE(head, node1, alist); # define QINSERT_BEFORE ( head , node , alist )do { *( head )-> alist .prev = ( node ); ( node )-> alist .prev = ( head )-> alist .prev; ( head )-> alist .prev = &( node )-> alist. next; ( node )-> alist .next = ( head ); } while (/* */0) 0x100 0 0x1a0 0x1a4 head 0x104 0x108 0x1a0 0 0x100 0x104 node0 0x1a4 0x1a8 0x200 0 0x200 0x204 node1 0x204 0x208 0x200 0 0x200 0x204 node1 0x204 0x208 0x100 0 0x1a0 0x1a4 head 0x104 0x108 0x1a0 0 0x100 0x104 node0 0x1a4 0x1a8
  • 28. Adding a Third Node QINSERT_BEFORE(head, node1, alist); # define QINSERT_BEFORE ( head , node1 , alist )do { *( head )-> alist .prev = ( node1 ); ( node1 )-> alist .prev = ( head )-> alist .prev; ( head )-> alist .prev = &( node1 )-> alist. next; ( node1 )-> alist .next = ( head ); } while (/* */0) (1) (1) 0x100 0 0x1a0 0x1a4 head 0x104 0x108 0x1a0 0 0x100 0x104 node0 0x1a4 0x1a8 0x100 0 0x1a0 0x1a4 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x200 0x204 node1 0x204 0x208 0x200 0 0x200 0x204 node1 0x204 0x208
  • 29. Adding a Third Node QINSERT_BEFORE(head, node1, alist); # define QINSERT_BEFORE ( head , node1 , alist )do { *( head )-> alist .prev = ( node1 ); ( node1 )-> alist .prev = ( head )-> alist .prev; ( head )-> alist .prev = &( node1 )-> alist. next; ( node1 )-> alist .next = ( head ); } while (/* */0) (1) (2) (2) 0x100 0 0x1a0 0x1a4 head 0x104 0x108 0x1a0 0 0x100 0x104 node0 0x1a4 0x1a8 0x100 0 0x1a0 0x1a4 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x200 0x204 node1 0x204 0x208 0x200 0 0x200 0x1a4 node1 0x204 0x208
  • 30. Adding a Third Node QINSERT_BEFORE(head, node1, alist); # define QINSERT_BEFORE ( head , node1 , alist )do { *( head )-> alist .prev = ( node1 ); ( node1 )-> alist .prev = ( head )-> alist .prev; ( head )-> alist .prev = &( node1 )-> alist. next; ( node1 )-> alist .next = ( head ); } while (/* */0) (3) (3) 0x100 0 0x1a0 0x1a4 head 0x104 0x108 0x1a0 0 0x100 0x104 node0 0x1a4 0x1a8 0x100 0 0x1a0 0x204 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x200 0x204 node1 0x204 0x208 0x200 0 0x200 0x1a4 node1 0x204 0x208 (1) (1) (2) (2)
  • 31. Adding a Third Node QINSERT_BEFORE(head, node1, alist); # define QINSERT_BEFORE ( head , node1 , alist )do { *( head )-> alist .prev = ( node1 ); ( node1 )-> alist .prev = ( head )-> alist .prev; ( head )-> alist .prev = &( node1 )-> alist. next; ( node1 )-> alist .next = ( head ); } while (/* */0) (1) (1) (2) (2) (3) (3) (4) (4) 0x100 0 0x1a0 0x1a4 head 0x104 0x108 0x1a0 0 0x100 0x104 node0 0x1a4 0x1a8 0x100 0 0x1a0 0x204 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x200 0x204 node1 0x204 0x208 0x200 0 0x100 0x1a4 node1 0x204 0x208
  • 32. Removing a Node QREMOVE(node0, alist); # define QREMOVE ( node , alist ) do { (1) *(( node )-> alist .prev) = ( node )-> alist .next; (2) (( node )-> alist .next)-> alist .prev = ( node )-> alist .prev;(3) ( node )-> alist .next = ( node ); (4) ( node )-> alist .prev = &(( node )-> alist .next); } while ( /* */ 0) 0x100 0 0x1a0 0x204 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208 0x100 0 ?? ?? head 0x104 0x108 0x1a0 0 ?? ?? node0 0x1a4 0x1a8 0x200 0 ?? ?? node1 0x204 0x208
  • 33. Removing a Node QREMOVE(node0, alist); # define QREMOVE ( node , alist ) do { *(( node )-> alist .prev) = ( node )-> alist .next; (( node )-> alist .next)-> alist .prev = ( node )-> alist .prev; ( node )-> alist .next = ( node ); ( node )-> alist .prev = &(( node )-> alist .next); } while ( /* */ 0) 0x100 0 0x1a0 0x204 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208 0x100 0 0x1a0 0x204 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208
  • 34. Removing a Node QREMOVE(node0, alist); # define QREMOVE ( node0 , alist ) do { (1) *(( node0 )->alist.prev) = ( node0 )->alist.next; (( node0 )->alist.next)->alist.prev = ( node0 )->alist.prev; ( node0 )->alist.next = ( node0 ); ( node0 )->alist.prev = &(( node0 )->alist.next); } while ( /* */ 0) (1) 0x100 0 0x200 0x204 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208 0x100 0 0x1a0 0x204 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208
  • 35. Removing a Node QREMOVE(node0, alist); # define QREMOVE ( node0 , alist ) do { *(( node0 )->alist.prev) = ( node0 )->alist.next; (2) (( node0 )->alist.next)->alist.prev = ( node0 )->alist.prev;( node0 )->alist.next = ( node0 ); ( node0 )->alist.prev = &(( node0 )->alist.next); } while ( /* */ 0) (2) 0x100 0 0x200 0x204 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x100 0x104 node1 0x204 0x208 0x100 0 0x1a0 0x204 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208
  • 36. Removing a Node QREMOVE(node0, alist); # define QREMOVE ( node0 , alist ) do { *(( node0 )->alist.prev) = ( node0 )->alist.next; (( node0 )->alist.next)->alist.prev = ( node0 )->alist.prev;(3) ( node0 )->alist.next = ( node0 ); ( node0 )->alist.prev = &(( node0 )->alist.next); } while ( /* */ 0) (3) 0x100 0 0x200 0x204 head 0x104 0x108 0x1a0 0 0x1a0 0x104 node0 0x1a4 0x1a8 0x200 0 0x100 0x104 node1 0x204 0x208 0x100 0 0x1a0 0x204 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208
  • 37. Removing a Node QREMOVE(node0, alist); # define QREMOVE ( node0 , alist ) do { *(( node0 )->alist.prev) = ( node0 )->alist.next; (( node0 )->alist.next)->alist.prev = ( node0 )->alist.prev;( node0 )->alist.next = ( node0 ); (4) ( node0 )->alist.prev = &(( node0 )->alist.next); } while ( /* */ 0) (4) 0x100 0 0x200 0x204 head 0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0 0x1a4 0x1a8 0x200 0 0x100 0x104 node1 0x204 0x208 0x100 0 0x1a0 0x204 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208
  • 38. Solution to Removing a Node QREMOVE(node0, alist); # define QREMOVE ( node , alist ) do { (1) *(( node )-> alist .prev) = ( node )-> alist .next; (2) (( node )-> alist .next)-> alist .prev = ( node )-> alist .prev;(3) ( node )-> alist .next = ( node ); (4) ( node )-> alist .prev = &(( node )-> alist .next); } while ( /* */ 0) 0x100 0 0x1a0 0x204 head 0x104 0x108 0x1a0 0 0x200 0x104 node0 0x1a4 0x1a8 0x200 0 0x100 0x1a4 node1 0x204 0x208 0x100 0 0x200 0x204 head 0x104 0x108 0x1a0 0 0x1a0 0x1a4 node0 0x1a4 0x1a8 0x200 0 0x100 0x104 node1 0x204 0x208
  • 39.
  • 40.
  • 41. Operator Precedence (from “C a Reference Manual”, 5 th Edition) 15 16 Precedence right-to-left unary address of & right-to-left unary indirection ( dereference ) * right-to-left unary negation, plus - + right-to-left unary logical not ! right-to-left unary bitwise not ~ right-to-left prefix increment, decrement ++ -- left-to-right postfix compound literal ( type ){ init } left-to-right postfix increment, decrement ++ -- left-to-right postfix direct selection . left-to-right postfix function call f (...) left-to-right postfix subscripting a [k] size indirect selection simple tokens Operator n/a primary names, literals right-to-left unary sizeof left to right postfix -> Associates Class Tokens 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Precedence right-to-left unary casts ( type ) left-to-right binary multiplicative * / % left-to-right binary additive + - sequential eval. assignment conditional logical or logical and bitwise or bitwise xor bitwise and equality/ineq. relational left, right shift Operator left-to-right binary , right-to-left binary = += -= *= /= %= &= ^= |= <<= >>= right-to-left ternary ?: left-to-right binary || left-to-right binary && left-to-right binary | left-to-right binary ^ left-to-right binary & left-to-right binary == != left-to-right binary < <= > >= left-to-right binary << >> Associates Class Tokens
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.