Programming Tutorials

C Tutorials

21. Using calloc() Function in C

By: Baski : 2007-10-03

Description: The calloc() function also allocates memory. Rather than allocating a group of bytes as malloc() does, calloc() allocates a group of objects. The function prototype is void *calloc(size_t num, size_t size);


22. Using realloc() Function in C

By: Charles : 2007-10-03

Description: The realloc() function changes the size of a block of memory that was previously allocated with malloc() or calloc(). The function prototype is void *realloc(void *ptr, size_t size);


23. Using free() Function in C

By: Daniel Malcolm : 2007-10-03

Description: When you allocate memory with either malloc() or calloc(), it is taken from the dynamic memory pool that is available to your program. This pool is sometimes called the heap, and it is finite. When your program finishes using a particular block of dynamically allocated memory, you should deallocate, or free, the memory to make it available for future use.


24. Using memset(), memcpy(), and memmove() in C

By: Emiley J : 2007-10-03

Description: Use memset() to initialize a block of memory to a specified value. Because this function can use only a type char as the initialization value, it is not useful for working with blocks of data types other than type char, except when you want to initialize to 0. In other words, it wouldn't be efficient to use memset() to initialize an array of type int to the value 99, but you could initialize all array elements to the value 0. memset() will be demonstrated in program below.


25. Using Shift Operators in C

By: Fazal : 2007-10-03

Description: Two shift operators shift the bits in an integer variable by a specified number of positions. The << operator shifts bits to the left, and the >> operator shifts bits to the right. The syntax for these binary operators is


26. Bitwise Logical Operators in C

By: Grenfel : 2007-10-03

Description: Three bitwise logical operators are used to manipulate individual bits in an integer data type, as shown in Table below. These operators have names similar to the TRUE/FALSE logical operators, but their operations differ.


27. Trigonometric, Hyperbolic, Exponential and Logarithmic Functions in C

By: Henry : 2007-10-03

Description: The following listing contains a single program that demonstrates several of the Math functions. However if you need to refer to other functions then you may look at the tables below.


28. assert() Function Example program in C

By: Jagan : 2007-10-03

Description: How do you use assert()? It is most frequently used to track down program bugs (which are distinct from compilation errors). A bug doesn't prevent a program from compiling, but it causes it to give incorrect results or to run improperly (locking up, for example). For instance, a financial-analysis program you're writing might occasionally give incorrect answers. You suspect that the problem is caused by the variable interest_rate taking on a negative value, which should never happen. To check this, place the statement


29. ERRNO.H Header File in C

By: Kamini : 2007-10-03

Description: The header file ERRNO.H defines several macros used to define and document runtime errors. These macros are used in conjunction with the perror() function.


30. Using qsort() and bsearch() with strings - example program in C

By: Manoj Kumar : 2007-10-03

Description: This program makes use of an array of pointers to strings.You can "sort" the strings by sorting the array of pointers. However, this method requires a modification in the comparison function. This function is passed pointers to the two items in the array that are compared. However, you want the array of pointers sorted based not on the values of the pointers themselves but on the values of the strings they point to.