CS1121_Spring_2011_Lecture10.BB

CS1121_Spring_2011_Lecture10.BB - CS1121 Introduction to C...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
CS1121 Introduction to C Computing Lecture 10 Continue OVERVIEW of C
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Outline Command line arguments review Structures in C (Contd.) Functions with structures as arguments Functions with two dimensional arrays as arguments
Background image of page 2
Command Line Arguments int main( int argc, char * argv[] ) argc Number of arguments (including program name) argv Array of char*s (that is, an array of ‘c’ strings) argv[0] : = program name argv[1] : = first argument argv[argc-1] := last argument
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Command Line Arguments #include <stdio.h> int main( int argc, char * argv[]) { int i; printf("%d arguments\n", argc); for (i = 0; i < argc; i++) printf(" %d: %s\n", i, argv[i]); return 0; }
Background image of page 4
Command Line Arguments $ ./a.our Midterm2 for CS1121 is on 3/31/11 7 arguments 0: ./a.out 1: Midterm2 2: for 3: cCS1121 4: is 5: on 6: 3/31/11 #include <stdio.h> int main(int argc, char* argv { int i; printf("%d arguments\n", ar for(i = 0; i < argc; i++) printf(" %d: %s\n", i, argv[i]); return 0; }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C structures C treats each structure as a unit as opposed to the “array” approach: a pointer to a collection of members in memory entire structures (not just pointers to structures) may be passed as function arguments, assigned to variables, etc. Structures cannot be compared using “ ==“
Background image of page 6
Structure declarations Combined variable and type declaration struct tag {member-list} variable-list; Any one of the three portions can be omitted struct {int a, b; char *p;} x, y;  /* omit tag */ variables x, y declared with members as described: int members a, b and char pointer p . x and y have same type, but differ from all others –
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Structure declarations struct S {int a, b; char *p;};  /* omit variables */ No variables are declared, but there is now a type struct S that can be referred to later struct S z;  /* omit members */
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/14/2011 for the course CSCI 1121 taught by Professor Haya during the Fall '11 term at GWU.

Page1 / 19

CS1121_Spring_2011_Lecture10.BB - CS1121 Introduction to C...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online