Category Archives: Programming with ‘C’

31. C – Union

Unions are conceptually similar to structures. The syntax to declare/define a union is also similar to that of a structure. The only differences is in terms of storage. In structure each member has its own storage location, whereas all members of union uses a single shared memory location which is equal to the size of its largest data member. This implies… Read More »

32. C – Functions

A function is a block of code that performs a specific task. C allows you to define functions according to your need. These functions are known as user-defined functions. For example: Suppose, you need to create a circle and color it depending upon the radius and color. You can create two functions to solve this… Read More »

33. C – Function Types

These 4 programs below check whether the integer entered by the user is a prime number or not. The output of all these programs below is the same, and we have created a user-defined function in each example. However, the approach we have taken in each example is different. Example 1: No arguments passed and… Read More »

34. C – Recursion

A function that calls itself is known as a recursive function. And, this technique is known as recursion. How recursion works? void recurse() { … .. … recurse(); … .. … } int main() { … .. … recurse(); … .. … } The recursion continues until some condition is met to prevent it. To… Read More »

35. C – Memory Management

This chapter explains dynamic memory management in C. The C programming language provides several functions for memory allocation and management. These functions can be found in the <stdlib.h> header file. Sr.No. Function & Description 1 void *calloc(int num, int size);This function allocates an array of num elements each of which size in bytes will be size. 2 void free(void *address);This… Read More »

36. C – File I/O

A file represents a sequence of bytes, regardless of it being a text file or a binary file. C programming language provides access on high level functions as well as low level (OS level) calls to handle file on your storage devices. This chapter will take you through the important calls for file management. Opening… Read More »

37. C – PreProcessors

The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process. In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. We’ll refer to the C Preprocessor as CPP. All preprocessor commands begin with… Read More »

38. C – Error Handling

Most of the C or even Unix function calls return -1 or NULL in case of any error and set an error code errno. It is set as a global variable and indicates an error occurred during any function call. You can find various error codes defined in <error.h> header file. So a C programmer can… Read More »

39. C – Command Line Arguments

It is possible to pass some values from the command line to your C programs when they are executed. These values are called command line arguments and many times they are important for your program especially when you want to control your program from outside instead of hard coding those values inside the code. The command line… Read More »