C Reference Card (ANSI) 2.2 (793752)
Текст из файла
C Reference Card (ANSI)ConstantsFlow of Controlsuffix: long, unsigned, float65536L, -1U, 3.0FProgram Structure/Functionsexponential form4.2e1prefix: octal, hexadecimal0, 0x or 0Xtype fnc(type 1 , . . . );function prototypeExample. 031 is 25, 0x31 is 49 decimaltype name;variable declarationcharacter constant (char, octal, hex)'a', '\ooo', '\xhh'int main(void) {main routine\n, \r, \t, \bdeclarationslocal variable declarations newline, cr, tab, backspacespecial characters\\, \?, \', \"statementsstring constant (ends with '\0')"abc. .
. de"}type fnc(arg 1 , . . . ) {function definitiondeclarationslocal variable declarations Pointers, Arrays & Structuresstatementsdeclare pointer to typetype *name;return value;declare function returning pointer to type type *f();}declare pointer to function returning type type (*pf)();/* */commentsgeneric pointer typevoid *int main(int argc, char *argv[])main with argsnull pointer constantNULLexit(arg);terminate executionobject pointed to by pointer*pointeraddress of object name&nameC Preprocessorarrayname[dim]include library file#include <filename>multi-dim arrayname[dim 1 ][dim 2 ].
. .include user file#include "filename"Structuresreplacement text#define name textstruct tag {structure templatereplacement macro#define name(var ) textdeclarationsdeclaration of membersExample. #define max(A,B) ((A)>(B) ? (A) : (B))};undefine#undef namecreate structurestruct tag namequoted string in replace#member of structure from templatename.memberExample. #define msg(A) printf("%s = %d", #A, (A))member of pointed-to structurepointer -> memberconcatenate args and rescan##Example.
(*p).x and p->x are the sameconditional execution#if, #else, #elif, #endifsingle object, multiple possible typesunionis name defined, not defined?#ifdef, #ifndefbit field with b bitsunsigned member : b;name defined?defined(name)line continuation char\Operators (grouped by precedence)Data Types/Declarationscharacter (1 byte)charintegerintreal number (single, double precision)float, doubleshort (16 bit integer)shortlong (32 bit integer)longdouble long (64 bit integer)long longpositive or negativesignednon-negative modulo 2munsignedpointer to int, float,.
. .int*, float*,. . .enumeration constantenum tag {name 1 =value 1 ,. . . };constant (read-only) valuetype const name;declare external variableexterninternal to source filestaticlocal persistent between callsstaticno valuevoidstructurestruct tag {. . . };create new name for data typetypedef type name;size of an object (type is size_t)sizeof objectsize of a data type (type is size_t)sizeof(type)Initializationinitialize variableinitialize arrayinitialize char stringtype name=value;type name[]={value 1 ,. . . };char name[]="string";c 2007 Joseph H.
Silverman Permissions on back. v2.2°statement terminator;block delimiters{ }exit from switch, while, do, forbreak;next iteration of while, do, forcontinue;go togoto label;labellabel: statementreturn value from functionreturn exprFlow Constructionsif statementif (expr 1 ) statement 1else if (expr 2 ) statement 2else statement 3while statementwhile (expr )statementfor statementfor (expr 1 ; expr 2 ; expr 3 )statementdo statementdostatementwhile(expr );switch statementswitch (expr ) {case const 1 : statement 1 break;case const 2 : statement 2 break;default: statement}ANSI Standard Libraries<assert.h><locale.h><stddef.h><ctype.h><math.h><stdio.h><errno.h><setjmp.h><stdlib.h><float.h><signal.h><string.h>Character Class Tests <ctype.h>struct member operatorstruct member through pointerincrement, decrementplus, minus, logical not, bitwise notindirection via pointer, address of objectcast expression to typesize of an objectname.memberpointer ->member++, -+, -, !, ~*pointer , &name(type) exprsizeofmultiply, divide, modulus (remainder)*, /, %add, subtract+, -alphanumeric?alphabetic?control character?decimal digit?printing character (not incl space)?lower case letter?printing character (incl space)?printing char except space, letter, digit?space, formfeed, newline, cr, tab, vtab?upper case letter?hexadecimal digit?convert to lower caseconvert to upper caseleft, right shift [bit ops]<<, >>String Operations <string.h>relational comparisonsequality comparisons>, >=, <, <===, !=and [bit op]&exclusive or [bit op]^or (inclusive) [bit op]|logical and&&logical or||conditional expressionexpr 1 ? expr 2 : expr 3assignment operators+=, -=, *=, .
. .expression evaluation separator,Unary operators, conditional expression and assignment operators group right to left; all others group left to right.<limits.h><stdarg.h><time.h>isalnum(c)isalpha(c)iscntrl(c)isdigit(c)isgraph(c)islower(c)isprint(c)ispunct(c)isspace(c)isupper(c)isxdigit(c)tolower(c)toupper(c)s is a string; cs, ct are constant stringslength of scopy ct to sconcatenate ct after scompare cs to ctonly first n charspointer to first c in cspointer to last c in cscopy n chars from ct to scopy n chars from ct to s (may overlap)compare n chars of cs with ctpointer to first c in first n chars of csput c into first n chars of sstrlen(s)strcpy(s,ct)strcat(s,ct)strcmp(cs,ct)strncmp(cs,ct,n)strchr(cs,c)strrchr(cs,c)memcpy(s,ct,n)memmove(s,ct,n)memcmp(cs,ct,n)memchr(cs,c,n)memset(s,c,n)C Reference Card (ANSI)Input/Output <stdio.h>Standard I/Ostandard input streamstdinstandard output streamstdoutstandard error streamstderrend of file (type is int)EOFget a charactergetchar()print a characterputchar(chr )print formatted dataprintf("format",arg 1 ,.
. . )print to string ssprintf(s,"format",arg 1 ,. . . )read formatted datascanf("format",&name 1 ,. . . )read from string ssscanf(s,"format",&name 1 ,. . . )print string sputs(s)File I/Odeclare file pointerFILE *fp;pointer to named filefopen("name","mode")modes: r (read), w (write), a (append), b (binary)get a charactergetc(fp)write a characterputc(chr ,fp)write to filefprintf(fp,"format",arg 1 ,. . . )read from filefscanf(fp,"format",arg 1 ,.
. . )read and store n elts to *ptrfread(*ptr,eltsize,n,fp)write n elts from *ptr to filefwrite(*ptr,eltsize,n,fp)close filefclose(fp)non-zero if errorferror(fp)non-zero if already reached EOFfeof(fp)read line to string s (< max chars)fgets(s,max,fp)write string sfputs(s,fp)Codes for Formatted I/O: "%-+ 0w.pmc"- left justify+ print with signspace print space if no sign0 pad with leading zerosw min field widthp precisionm conversion character:h short,l long,L long doublecconversion character:d,i integeru unsignedc single chars char stringf double (printf)e,E exponentialf float (scanf)lf double (scanf)o octalx,X hexadecimalp pointern number of chars writteng,G same as f or e,E depending on exponentVariable Argument Lists <stdarg.h>declaration of pointer to argumentsva_list ap;initialization of argument pointerva_start(ap,lastarg);lastarg is last named parameter of the functionaccess next unnamed arg, update pointer va_arg(ap,type)call before exiting functionva_end(ap);Standard Utility Functions <stdlib.h>absolute value of int nabs(n)absolute value of long nlabs(n)quotient and remainder of ints n,ddiv(n,d)returns structure with div_t.quot and div_t.remquotient and remainder of longs n,dldiv(n,d)returns structure with ldiv_t.quot and ldiv_t.rempseudo-random integer [0,RAND_MAX]rand()set random seed to nsrand(n)terminate program executionexit(status)pass string s to system for executionsystem(s)Conversionsconvert string s to doubleatof(s)convert string s to integeratoi(s)convert string s to longatol(s)convert prefix of s to doublestrtod(s,&endp)convert prefix of s (base b) to longstrtol(s,&endp,b)same, but unsigned longstrtoul(s,&endp,b)Storage Allocationallocate storagemalloc(size), calloc(nobj,size)change size of storagenewptr = realloc(ptr,size);deallocate storagefree(ptr);Array Functionssearch array for keybsearch(key,array,n,size,cmpf)sort array ascending orderqsort(array,n,size,cmpf)Time and Date Functions <time.h>processor time used by programclock()Example.
clock()/CLOCKS_PER_SEC is time in secondscurrent calendar timetime()time2 -time1 in seconds (double)difftime(time2 ,time1 )arithmetic types representing timesclock_t,time_tstructure type for calendar time compsstruct tmtm_secseconds after minutetm_minminutes after hourtm_hourhours since midnighttm_mdayday of monthtm_monmonths since Januarytm_yearyears since 1900tm_wdaydays since Sundaytm_ydaydays since January 1tm_isdstDaylight Savings Time flagconvert local time to calendar timemktime(tp)convert time in tp to stringasctime(tp)convert calendar time in tp to local time ctime(tp)convert calendar time to GMTgmtime(tp)convert calendar time to local timelocaltime(tp)format date and time infostrftime(s,smax,"format",tp)tp is a pointer to a structure of type tmMathematical Functions <math.h>Arguments and returned values are doubletrig functionsinverse trig functionsarctan(y/x)hyperbolic trig functionsexponentials & logsexponentials & logs (2 power)division & remainderpowers (float)roundingsin(x), cos(x), tan(x)asin(x), acos(x), atan(x)atan2(y,x)sinh(x), cosh(x), tanh(x)exp(x), log(x), log10(x)ldexp(x,n), frexp(x,&e)modf(x,ip), fmod(x,y)pow(x,y), sqrt(x)ceil(x), floor(x), fabs(x)Integer Type Limits <limits.h>The numbers given in parentheses are typical values for theconstants on a 32-bit Unix system, followed by minimum required values (if significantly different).CHAR_BIT bits in char(8)CHAR_MAX max value of char(SCHAR_MAX or UCHAR_MAX)CHAR_MIN min value of char(SCHAR MIN or 0)SCHAR_MAX max signed char(+127)SCHAR_MIN min signed char(−128)SHRT_MAX max value of short(+32,767)SHRT_MIN min value of short(−32,768)INT_MAX max value of int(+2,147,483,647) (+32,767)INT_MIN min value of int(−2,147,483,648) (−32,767)LONG_MAX max value of long(+2,147,483,647)LONG_MIN min value of long(−2,147,483,648)UCHAR_MAX max unsigned char(255)USHRT_MAX max unsigned short(65,535)UINT_MAX max unsigned int(4,294,967,295) (65,535)ULONG_MAX max unsigned long(4,294,967,295)Float Type Limits <float.h>The numbers given in parentheses are typical values for theconstants on a 32-bit Unix system.FLT_RADIXradix of exponent rep(2)FLT_ROUNDSfloating point rounding modeFLT_DIGdecimal digits of precision(6)FLT_EPSILONsmallest x so 1.0f + x 6= 1.0f(1.1E − 7)FLT_MANT_DIG number of digits in mantissaFLT_MAXmaximum float number(3.4E38)FLT_MAX_EXPmaximum exponentFLT_MINminimum float number(1.2E − 38)FLT_MIN_EXPminimum exponentDBL_DIGdecimal digits of precision(15)DBL_EPSILONsmallest x so 1.0 + x 6= 1.0(2.2E − 16)DBL_MANT_DIG number of digits in mantissaDBL_MAXmax double number(1.8E308)DBL_MAX_EXPmaximum exponentDBL_MINmin double number(2.2E − 308)DBL_MIN_EXPminimum exponentc 2007 Joseph H.
SilvermanJanuary 2007 v2.2. Copyright °Permission is granted to make and distribute copies of this card provided the copyright notice and this permission notice are preserved onall copies.Send comments and corrections to J.H. Silverman, Math. Dept., BrownUniv., Providence, RI 02912 USA. hjhs@math.brown.edui.
Характеристики
Тип файла PDF
PDF-формат наиболее широко используется для просмотра любого типа файлов на любом устройстве. В него можно сохранить документ, таблицы, презентацию, текст, чертежи, вычисления, графики и всё остальное, что можно показать на экране любого устройства. Именно его лучше всего использовать для печати.
Например, если Вам нужно распечатать чертёж из автокада, Вы сохраните чертёж на флешку, но будет ли автокад в пункте печати? А если будет, то нужная версия с нужными библиотеками? Именно для этого и нужен формат PDF - в нём точно будет показано верно вне зависимости от того, в какой программе создали PDF-файл и есть ли нужная программа для его просмотра.