background preloader

Programming

Facebook Twitter

(c++) How do you typedef a function pointer type. C++ QUICK REFERENCE. Matt Mahoney, mmahoney@cs.fit.edu // Comment to end of line /* Multi-line comment */ #include <stdio.h> // Insert standard header file #include "myfile.h" // Insert file in current directory #define X some text // Replace X with some text #define F(a,b) a+b // Replace F(1,2) with 1+2 #define X \ some text // Line continuation #undef X // Remove definition #if defined(X) // Condional compilation (#ifdef X) #else // Optional (#ifndef X or #if !

C++ QUICK REFERENCE

Defined(X)) #endif // Required after #if, #ifdef 255, 0377, 0xff // Integers (decimal, octal, hex) 2147483647L, 0x7fffffffl // Long (32-bit) integers 123.0, 1.23e2 // double (real) numbers 'a', '\141', '\x61' // Character (literal, octal, hex) '\n', '\\', '\'', '\"' // Newline, backslash, single quote, double quote "string\n" // Array of characters ending with newline and \0 "hello" "world" // Concatenated strings true, false // bool constants 1 and 0 Function parameters and return values may be of any type. STDIO.H, CSTDIO (Input/output) How exactly to use extern? Que significa %d, %f, %s en programacion C++ #pragma - C and C++ Syntax Reference. Tutorials - C Preprocessor Tricks. The C preprocessor modifies a source code file before handing it over to the compiler.

Tutorials - C Preprocessor Tricks

You're most likely used to using the preprocessor to include files directly into other files, or #define constants, but the preprocessor can also be used to create "inlined" code using macros expanded at compile time and to prevent code from being compiled twice. There are essentially three uses of the preprocessor--directives, constants, and macros.

Directives are commands that tell the preprocessor to skip part of a file, include another file, or define a constant or macro. Directives always begin with a sharp sign (#) and for readability should be placed flush to the left of the page. All other uses of the preprocessor involve processing #define'd constants or macros. Header Files The #include directive tells the preprocessor to grab the text of a file and place it directly into the current file. Serial Port and Nammed pipe. Input/Output with files. C++ provides the following classes to perform output and input of characters to/from files: ofstream: Stream class to write on filesifstream: Stream class to read from filesfstream: Stream class to both read and write from/to files.

Input/Output with files

These classes are derived directly or indirectly from the classes istream and ostream. We have already used objects whose types were these classes: cin is an object of class istream and cout is an object of class ostream. Therefore, we have already been using classes that are related to our file streams. And in fact, we can use our file streams the same way we are already used to use cin and cout, with the only difference that we have to associate these streams with physical files. Let's see an example: This code creates a file called example.txt and inserts a sentence into it in the same way we are used to do with cout, but using the file stream myfile instead.

Printf. Function int printf ( const char * format, ... ); Print formatted data to stdout Writes the C string pointed by format to the standard output (stdout).

printf

If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers. Parameters format C string that contains the text to be written to stdout. A format specifier follows this prototype: [see compatibility note below] %[flags][width][.precision][length]specifier Where the specifier character at the end is the most significant component, since it defines the type and the interpretation of its corresponding argument: The format specifier can also contain sub-specifiers: flags, width, .precision and modifiers (in that order), which are optional and follow these specifications: The length sub-specifier modifies the length of the data type. Note: Yellow rows indicate specifiers and sub-specifiers introduced by C99.

Pointers. In earlier chapters, variables have been explained as locations in the computer's memory which can be accessed by their identifier (their name).

Pointers

This way, the program does not need to care about the physical address of the data in memory; it simply uses the identifier whenever it needs to refer to the variable. For a C++ program, the memory of a computer is like a succession of memory cells, each one byte in size, and each with a unique address. These single-byte memory cells are ordered in a way that allows data representations larger than one byte to occupy memory cells that have consecutive addresses. This way, each cell can be easily located in the memory by means of its unique address. For example, the memory cell with the address 1776 always follows immediately after the cell with address 1775 and precedes the one with 1777, and is exactly one thousand cells after 776 and exactly one thousand cells before 2776. Address-of operator (&) Become a Programmer, Motherfucker. If you don't know how to code, then you can learn even if you think you can't.

Become a Programmer, Motherfucker

Thousands of people have learned programming from these fine books: Learn Python The Hard Way Learn Ruby The Hard Way Learn Code The Hard Way I'm also working on a whole series of programming education books at learncodethehardway.org. Learn C The Hard Way Learn SQL The Hard Way Learn Regex The Hard Way. RL-ARM User's Guide: os_mut_wait Library Routine. Public, private, protected...?(C++) Quote: A class, very simply put, is a struct : it contains variables (which are called members in this contexts) and functions, called methods.

public, private, protected...?(C++)

However, it's how you access them that really makes a change. As for public et al, I like to use to following analogy. Think of your house as a class. Code: Think about it. Private members/methods are like things you put inside your safe. Protected is the middle point : only some parts of your program can access it. Inheritance and friend functions are another topic entirely. As for the '::', I was confused by it too. The last lines mean "define myInteger's changeInt method".