C-cheat-sheet - C Reference Card(ANSI Program...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C Reference Card (ANSI) Program Structure/Functions type fnc ( type 1 , . . . ) function declarations type name external variable declarations main() { main routine declarations local variable declarations statements } type fnc ( arg 1 , . . . ) { function definition declarations local variable declarations statements return value ; } /* */ comments main(int argc, char *argv) main with args exit( arg ) terminate execution C Preprocessor include library file #include < filename > include user file #include " filename " replacement text #define name text replacement macro #define name ( var ) text Example . #define max(A,B) ((A)>(B) ? (A) : (B)) undefine #undef name quoted string in replace # concatenate args and rescan ## conditional execution #if, #else, #elif, #endif is name defined, not defined? #ifdef, #ifndef name defined? defined( name ) line continuation char \ Data Types/Declarations character (1 byte) char integer int float (single precision) float float (double precision) double short (16 bit integer) short long (32 bit integer) long positive and negative signed only positive unsigned pointer to int , float , . . . *int, *float, . . . enumeration constant enum constant (unchanging) value const declare external variable extern register variable register local to source file static no value void structure struct create name by data type typedef typename size of an object (type is size_t ) sizeof object size of a data type (type is size_t ) sizeof( type name ) Initialization initialize variable type name = value initialize array type name ={ value 1 , . . . } initialize char string char name =" string " c 1999 Joseph H. Silverman Permissions on back. v1.3 Constants long (suffix) L or l float (suffix) F or f exponential form e octal (prefix zero) hexadecimal (prefix zero-ex) 0x or 0X character constant (char, octal, hex) 'a', '\ ooo ', '\x hh ' newline, cr, tab, backspace \n, \r, \t, \b special characters \\, \?, \', \" string constant (ends with '\0' ) "abc . . . de" Pointers, Arrays & Structures declare pointer to type type * name declare function returning pointer to type type *f() declare pointer to function returning type type (*pf)() generic pointer type void * null pointer NULL object pointed to by pointer * pointer address of object name & name array name [ dim ] multi-dim array name [ dim 1 ][ dim 2 ] . . . Structures struct tag { structure template declarations declaration of members }; create structure struct tag name member of structure from template name . member member of pointed to structure pointer-> member Example . (*p).x and p->x are the same single value, multiple type structure...
View Full Document

This document was uploaded on 06/12/2011.

Page1 / 2

C-cheat-sheet - C Reference Card(ANSI Program...

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

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