Created
July 29, 2012 01:14
-
-
Save hfadev/3195584 to your computer and use it in GitHub Desktop.
C: Reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //copy n integer | |
| //string.h | |
| memcpy(dest,from,sizeof(int)*n); | |
| //memory management | |
| //stdlib.h | |
| void f(){ | |
| int* numberList = (int*) malloc(sizeof(int) * 1000); | |
| numberList = (int*)realloc(numberList,100); | |
| //... | |
| free(numberList); // when function terminates numberList varible disapper but memory remains allocated, so free | |
| } | |
| printf("%d",FOPEN_MAX);//max # of files that can be simultaneously opened | |
| printf("%d",FILENAME_MAX);//max lenght of a filename | |
| //division | |
| //stdlib.h | |
| div_t d; | |
| d = div(9,4); | |
| printf("%d\n",d.quot); //2 | |
| printf("%d\n",d.rem); //1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //conditional include | |
| #include "settings.h" | |
| #if VERSION == 0 //defined in settings.h | |
| #define VERSION_H "test.h" | |
| #elif VERSION == 1 | |
| #define VERSION_H "debug.h" | |
| #else | |
| #define VERSION_H "production.h" | |
| #endif | |
| #include VERSION_H | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment