next up previous contents index
Next: Preprocessor directives Up: Some hilights of the Previous: Reading and Writing: disk   Contents   Index


Miscellaneous


exit

exit causes immediate termination of the program. (Declared in stdlib.h.) (In windows programs, HaltCL should be used instead.)

  
void exit(int status);


time

(Non-standard) time returns the number of seconds elapsed since 00:00:00 GMT, January 1, 1970. (Declared in time.h.)

  
time_t time(time_t *tp);  /*  time_t is a pre-defined integer type  */
If tp is not NULL, the number of seconds is also stored in tp. For example:

  
printf("There have elapsed %li seconds since 00:00:00 GMT, January 1", 
       (long)time(NULL));  /*  assumes time_t is a long int  */
Another common use is to seed the random number generator:

  
srand48((long)time(NULL));  /*  time is declared in time.h  */


argc and argv - accessing command line arguments

We will not discuss this here.


malloc

malloc is used to request blocks of memory at runtime. (Declared in stdlib.h.)

  
void *malloc(size_t size);  /*  size_t is a predefined integer type  */
The return value is a pointer to the start of a contiguous block of memory of size bytes. When the memory has been finished with, you can release it by calling free. If there is not enough memory available to satisfy the request, malloc returns NULL.


free

free releases memory previously allocated by malloc. (Declared in stdlib.h.)

  
void free(void *p);


sizeof

sizeof returns the number of bytes occupied by a variable or type (it is not actually part of the standard C library but part of the C language, so you do not need to #include a header file to use it). For example:

  
int i;
/* .. */
printf("ints occupy %d bytes",sizeof(i)");  /*  sizeof(int) works too  */


next up previous contents index
Next: Preprocessor directives Up: Some hilights of the Previous: Reading and Writing: disk   Contents   Index
CATAM admin 2010-02-23