c 2b 2b cheat sheet

Solutions on MaxInterview for c 2b 2b cheat sheet by the best coders in the world

showing results for - "c 2b 2b cheat sheet"
Giacomo
26 Jul 2018
1255, 0377, 0xff             // Integers (decimal, octal, hex)
22147483647L, 0x7fffffffl    // Long (32-bit) integers
3123.0, 1.23e2               // double (real) numbers
4'a', '\141', '\x61'         // Character (literal, octal, hex)
5'\n', '\\', '\'', '\"'      // Newline, backslash, single quote, double quote
6"string\n"                  // Array of characters ending with newline and \0
7"hello" "world"             // Concatenated strings
8true, false                 // bool constants 1 and 0
9nullptr                     // Pointer type with the address of 0
Leuan
21 Apr 2019
1                            // Comment to end of line
2                            /* Multi-line comment */
3#include  <stdio.h>         // Insert standard header file
4#include "myfile.h"         // Insert file in current directory
5#define X some text         // Replace X with some text
6#define F(a,b) a+b          // Replace F(1,2) with 1+2
7#define X \
8 some text                  // Multiline definition
9#undef X                    // Remove definition
10#if defined(X)              // Conditional compilation (#ifdef X)
11#else                       // Optional (#ifndef X or #if !defined(X))
12#endif                      // Required after #if, #ifdef
Stone
23 Jul 2016
1x=y;                        // Every expression is a statement
2int x;                      // Declarations are statements
3;                           // Empty statement
4{                           // A block is a single statement
5    int x;                  // Scope of x is from declaration to end of block
6}
7if (x) a;                   // If x is true (not 0), evaluate a
8else if (y) b;              // If not x and y (optional, may be repeated)
9else c;                     // If not x and not y (optional)
10
11while (x) a;                // Repeat 0 or more times while x is true
12
13for (x; y; z) a;            // Equivalent to: x; while(y) {a; z;}
14
15for (x : y) a;              // Range-based for loop e.g.
16                            // for (auto& x in someList) x.y();
17
18do a; while (x);            // Equivalent to: a; while(x) a;
19
20switch (x) {                // x must be int
21    case X1: a;             // If x == X1 (must be a const), jump here
22    case X2: b;             // Else if x == X2, jump here
23    default: c;             // Else jump here (optional)
24}
25break;                      // Jump out of while, do, or for loop, or switch
26continue;                   // Jump to bottom of while, do, or for loop
27return x;                   // Return x from function to caller
28try { a; }
29catch (T t) { b; }          // If a throws a T, then jump here
30catch (...) { c; }          // If a throws something else, jump here