Crayon Syntax Highlighter Test

Switch to Crayon Syntax Highlighter, Just a test…

I'm a pre!
1
2
3
4
5
6
7
8
9
10
11
// From http://stroustrup.com/bs_faq2.html
  int a = 7;
  double* p1 = (double*) &a;           // ok (but a is not a double)
  double* p2 = static_cast<double*>(&a);  // error
  double* p2 = reinterpret_cast<double*>(&a); // ok: I really mean it

  const int c = 7;
  int* q1 = &c;         // error
  int* q2 = (int*)&c;      // ok (but *q2=2; is still invalid code and may fail)
  int* q3 = static_cast<int*>(&c);    // error: static_cast doesn't cast away const
  int* q4 = const_cast<int*>(&c); // I really mean it

I don’t remember any deep thoughts or involved discussions about the order at the time. A few of the early users - notably me - simply liked the look of {cpp} const int c = 10; {/cpp} better than {cpp} int const c = 10; {/cpp} at the time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# From http://docs.python.org/py3k/tutorial/stdlib2.html
import struct

data = open('myfile.zip', 'rb').read()
start = 0
for i in range(3):                      # show the first 3 file headers
    start += 14
    fields = struct.unpack('<IIIHH', data[start:start+16])
    crc32, comp_size, uncomp_size, filenamesize, extra_size = fields

    start += 16
    filename = data[start:start+filenamesize]
    start += filenamesize
    extra = data[start:start+extra_size]
    print(filename, hex(crc32), comp_size, uncomp_size)

    start += extra_size + comp_size     # skip to the next header
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

int main()
{
  static int arr[100];
  int c; // This is a special var
  cout << "Input a index";
  cin >> c;
  cout << arr[c] << endl; // arr[c] is special, too!
}

Comments