Presentation is loading. Please wait.

Presentation is loading. Please wait.

C Language Summary HTML version. I/O Data Types Expressions Functions Loops and Decisions Preprocessor Statements.

Similar presentations


Presentation on theme: "C Language Summary HTML version. I/O Data Types Expressions Functions Loops and Decisions Preprocessor Statements."— Presentation transcript:

1 C Language Summary HTML version

2 I/O Data Types Expressions Functions Loops and Decisions Preprocessor Statements

3 0. I/O: Output printf( “ format_list ”, var_list ); All formats are of the form: %w.px%w.px where w.p is optional and can be *.* (value given by next 2 arguments ). w  field width p  the precision x  d (integer), f (decimal ), e (e-format), g (g-format), s (string), c (character) …

4 0. I/O: Input scanf( “ format_list ”, pointer_list ); Notes: &var is a pointer pointing to the variable var. Separators can be specified in the format_list. e.g., “%d:%d” expects input of 2 integers separated by an :. A string variable is already a pointer so that no preceding & is needed.

5 0. I/O: fopen #include  stdio.h  /* for the fopen() */ #include  stdlib.h  /* for the exit() */ int main( int argc, char* argv[] ) { FILE *in_file, *fopen( ); in_file  fopen( “file_name”, ”w+” );/* in_file is the file handle */ if ( in_file   NULL ) { printf( “ Can’t open file. \n” ); exit(1);/* program is terminated with exit code equal to 1 */ } fprintf( in_file, "Hello World!\n"); return 0; }

6 0. I/O: rewind fclose fprintf scanf rewind( in_file ); fclose( in_file ); fprintf( out_file, “ format_list ”, var_list ); Note: printf is fprintf with out_file  stdout. fscanf( in_file, “ format_list ”, var_list ); Note: scanf is fscanf with in_file  stdin IO.c

7 1. Data Types: Basic Data Types Declaration & initialization ( can be placed anywhere ): type var1  initial_value1, …, varN  initial_valueN; Assignment: var1  var2  …  value;

8 TypeModifiers intshort, long, unsigned floatlong (double) charunsigned void  Basic Data Types

9 Derived Data Types: Arrays Declaration & initialization: type var[n]  { var[0], …, var[n-1] }; /* RHS is the initial value of the array */ char cvar[ ]  “String”; type var[n][m]  { { var[0][0], …, var[0][m-1] }, …, { var[n-1][0], …, var[n-1][m-1] } };

10 Structures Definition & declaration: struct structure_name { member1_declaration; … memberN_declaration; } var_list;

11 Declaration: struct structure_name var_list; Definition, declaration & initialization: struct structure_name { member1_declaration; … memberN_declaration; } var  { member1  value1, …, memberN  valueN };

12 Unions Every member of a union shares the same memory space. Definition & declaration: union union_name { member1_declaration; … memberN_declaration; } var_list; Declaration: union union _name var_list;

13 Pointers Definition: type *pointer_name; /* The ‘*’ denotes a pointer variable */ Example: struct struct_name ( *fn_pointer ) ( ) ; declares fn_pointer to be a pointer to a function that returns a struct_name structure.

14 Enumerated Data Types Definition & declaration: enum enum_name { enum_1, …, enum_N } var_list; Declaration: enum enum _name var_list;

15 typedef typedef assigns a new name to a datatype. Example: typedef struct { member1_declaration; … memberN_declaration; } struct_name; struct_name var; /* This declares var to be a struct_name structure. */


Download ppt "C Language Summary HTML version. I/O Data Types Expressions Functions Loops and Decisions Preprocessor Statements."

Similar presentations


Ads by Google