Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
[C Frequently
What is the difference between a string copy (strcpy) and a memory copy
(memcpy)? When should each be used?
The strcpy() function is designed to work exclusively with strings. It copies each byte
of the source string to the destination string and stops when the terminating null
character () has been moved. On the other hand, the memcpy() function is designed
to work with any type of data. Because not all data ends with a null character, you
must provide the memcpy() function with the number of bytes you want to copy
from the source to the destination.
Is it possible to execute code even after the program exits the main() function?
The standard C library provides a function named atexit() that can be used to
perform cleanup operations when your program terminates. You can set up a set of
functions you want to perform automatically when your program exits by passing
function pointers to the at exit() function.
What is Preprocessor?
The preprocessor is used to modify your program according to the preprocessor
directives in your source code. Preprocessor directives (such as #define) give the
preprocessor specific instructions on how to modify your source code. The
preprocessor reads in all of your include files and the source code you are compiling
and creates a preprocessed version of your source code. This preprocessed version
has all of its macros and constant symbols replaced by their corresponding code
and value assignments. If your source code contains any conditional preprocessor
directives (such as #if), the preprocessor evaluates the condition and modifies your
source code accordingly.
The preprocessor contains many features that are powerful to use, such as creating
macros, performing conditional compilation, inserting predefined environment
variables into your code, and turning compiler features on and off. For the
professional programmer, in-depth knowledge of the features of the preprocessor
can be one of the keys to creating fast, efficient programs.
the old size and if sufficient space is not available subsequent to the old region, the
function realloc( ) may create a new region and all the old data are moved to the
new region.