Skip to content

Instantly share code, notes, and snippets.

@hfadev
Created July 29, 2012 01:14
Show Gist options
  • Select an option

  • Save hfadev/3195584 to your computer and use it in GitHub Desktop.

Select an option

Save hfadev/3195584 to your computer and use it in GitHub Desktop.
C: Reference
//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
//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