Category Archives: Programming with ‘C’

21. C – Arrays & Functions

Pass arrays to a function in C In C programming, you can pass an entire array to functions. Before we learn that, let’s see how you can pass individual elements of an array to functions. Passing individual array elements Passing array elements to a function is similar to passing variables to a function. Example 1: Passing… Read More »

22. C – Strings

In C programming, a string is a sequence of characters terminated with a null character \0. For example: When the compiler encounters a sequence of characters enclosed in the double quotation marks, it appends a null character \0 at the end by default. Strings are actually a one-dimensional array of characters terminated by a null character ‘\0’. Thus a null-terminated… Read More »

23. C – Pointers

Pointers in C are easy and fun to learn. Some C programming tasks are performed more easily with pointers, and other tasks, such as dynamic memory allocation, cannot be performed without using pointers. So it becomes necessary to learn pointers to become a perfect C programmer. Let’s start learning them in simple and easy steps.… Read More »

24. C – Pointer Arithmetic and Comparision

A pointer in c is an address, which is a numeric value. Therefore, you can perform arithmetic operations on a pointer just as you can on a numeric value. There are four arithmetic operators that can be used on pointers: ++, –, +, and – To understand pointer arithmetic, let us consider that ptr is an integer… Read More »

25. C – Null Pointer

A null pointer is a pointer which points nothing. Some uses of the null pointer are: To initialize a pointer variable when that pointer variable isn’t assigned any valid memory address yet. To pass a null pointer to a function argument when we don’t want to pass any valid memory address. To check for a… Read More »

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 »