Category Archives: Library

26. C – Strings to Pointer

In this tutorial we will learn to store strings using pointers in C programming language. We know that a string is a sequence of characters which we save in an array. And in C programming language the \0 null character marks the end of a string. Creating a string In the following example we are creating a string str using char character array… Read More »

27. C – Arrays of Pointer

An array is a block of sequential data. Let’s write a program to print addresses of array elements. Output &x[0] = 1450734448 &x[1] = 1450734452 &x[2] = 1450734456 &x[3] = 1450734460 Address of array x: 1450734448 There is a difference of 4 bytes between two consecutive elements of array x. It is because the size of int is… Read More »

28. C – Structure (struct)

In C programming, a struct (or structure) is a collection of variables (can be of different types) under a single name. How to define structures? Before you can create structure variables, you need to define its data type. To define a struct, the struct keyword is used. Syntax of struct struct structureName { dataType member1; dataType member2;… Read More »

30. Pointers to Structures

Dot(.) operator is used to access the data using normal structure variable and arrow (->) is used to access the data using a pointer variable. You have learned how to access structure data using normal variables in C – Structure topic. So, we are showing here how to access structure data using the pointer variable in the below… Read More »

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 »