Guia rapida de c

Páginas: 12 (2759 palabras) Publicado: 8 de octubre de 2010
C++ QUICK REFERENCE
PREPROCESSOR
// /* // // // // // // // // // Comment to end of line Multi-line comment */ Insert standard header file Insert file in current directory Replace X with some text Replace F(1,2) with 1+2 Line continuation Remove definition Condional compilation (#ifdef X) Optional (#ifndef X or #if !defined(X)) Required after #if, #ifdef

const int c=3; to const int* p=a;int* const p=a; const int* const p=a; const int& cr=x;

// Constants must be initialized, cannot assign // // // // Contents of p (elements of a) are constant p (but not contents) are constant Both p and its contents are constant cr cannot be assigned to change x

STORAGE CLASSES
int x; static int x; extern int x; // Auto (memory exists only while in scope) // Global lifetime even if local scope// Information only, declared elsewhere

#include #include "myfile.h" #define X some text #define F(a,b) a+b #define X \ some text #undef X #if defined(X) #else #endif

STATEMENTS
x=y; int x; ; { int x; block a; } if (x) a; else if (y) b; else c; while (x) a; for (x; y; z) a; do a; while (x); // Every expression is a statement // Declarations are statements // Empty statement // A block isa single statement // Scope of x is from declaration to end of // In C, declarations must precede statements // If x is true (not 0), evaluate a // If not x and y (optional, may be repeated) // If not x and not y (optional) // Repeat 0 or more times while x is true // Equivalent to: x; while(y) {a; z;} // Equivalent to: a; while(x) a; // // // // x must be int If x == X1 (must be a const), jumphere Else if x == X2, jump here Else jump here (optional)

LITERALS

255, 0377, 0xff 2147483647L, 0x7fffffffl 123.0, 1.23e2 'a', '\141', '\x61' '\n', '', ''', '"' quote "string\n" \0 "hello" "world" true, false

// // // // //

Integers (decimal, octal, hex) Long (32-bit) integers double (real) numbers Character (literal, octal, hex) Newline, backslash, single quote, double

// Array ofcharacters ending with newline and // Concatenated strings // bool constants 1 and 0

DECLARATIONS
int x; // Declare x to be an integer (value undefined) int x=255; // Declare and initialize x to 255 short s; long l; // Usually 16 or 32 bit integer (int may be either) char c='a'; // Usually 8 bit character unsigned char u=255; signed char s=-1; // char might be either unsigned long x=0xffffffffL;// short, int, long are signed float f; double d; // Single or double precision real (never unsigned) bool b=true; // true or false, may also use int (1 or 0) int a, b, c; // Multiple declarations int a[10]; // Array of 10 ints (a[0] through a[9]) int a[]={0,1,2}; // Initialized array (or a[3]={0,1,2}; ) int a[2][3]={{1,2,3},{4,5,6}}; // Array of array of ints char s[]="hello"; // String (6elements including '\0') int* p; // p is a pointer to (address of) int char* s="hello"; // s points to unnamed array containing "hello" void* p=NULL; // Address of untyped memory (NULL is 0) int& r=x; // r is a reference to (alias of) int x enum weekend {SAT,SUN}; // weekend is a type with values SAT and SUN enum weekend day; // day is a variable of type weekend enum weekend {SAT=0,SUN=1}; // Explicitrepresentation as int enum {SAT,SUN} day; // Anonymous enum typedef String char*; // String s; means char* s; switch (x) { case X1: a; case X2: b; default: c; } break; continue; return x; try { a; } catch (T t) { b; } catch (...) { c; }

// Jump out of while, do, or for loop, or switch // Jump to bottom of while, do, or for loop // Return x from function to caller // If a throws a T, then jumphere // If a throws something else, jump here

FUNCTIONS
int f(int x, int); int void f(); void f(int a=0); f(); inline f(); f() { statements; } T operator+(T x, T y); T operator-(T x); T operator++(int); extern "C" {void f();} // f is a function taking 2 ints and returning // // // // // // // // // f is a procedure taking no arguments f() is equivalent to f(0) Default return type is int...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • guia rapida
  • Guia Rapida
  • Guía Muy Rápida
  • Guia Rapida
  • Guias Rapidas
  • Lenguaje C, resumen rápido
  • Resumen rapido C
  • Resumen rápido c

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS