Files are used to store data permanently on hard disk. C programming supports built in library function to interact with files and directories. I have compiled a list of file handling exercises with solution for beginners and intermediate programmers.
Programming
Pointer programming exercises and solutions in C
Pointer is a variable that stores memory addresses. Unlike normal variables it does not store user given or processed value, instead it stores valid computer memory address.
How to pass and return array from function in C?
Functions makes our program modular and maintainable. Big applications can have hundreds of functions.
Array is a data structure to store homogeneous collection of data. Arrays are equally important as functions. In programming we often use arrays and functions together.
Here in this post I will explain how to pass and return array from function in C programming.
C program to input and print array elements using pointers
Write a C program to input elements in an array and print array using pointers. How to input and display array elements using pointer in C programming.
Example
Input
Input array size: 10 Input elements: 1 2 3 4 5 6 7 8 9 10
Output
Array elements: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Function pointer in C
Quick links
In this ongoing C programming tutorial series, we learnt many concepts related to function and pointers. Let us give a quick recall.
A function is a collection of statements grouped together to perform a task. Function encapsulates behaviour and allows us to write modular and reusable code. Instead of writing same code to perform an action ‘A’ repeatedly, we call a function that encapsulates action ‘A’.
void pointer or generic pointer in C – use and arithmetic
Pointer is a variable pointing at a memory location of specific type. Type defines many important properties related to the pointer. Such as valid memory addresses it can point, pointer arithmetic, etc.
As per C programming semantics, you must specify pointer type during its declaration. Also, it is illegal to point pointer of one type to object of another type. For example, int
pointer cannot point to a float
variable.
Constant pointer and pointer to constant in C
Pointers are the most powerful as well as complex component of C programming. For newbies, it’s like learning rocket science in C. However, I have tried my best to simplify things.
In this ongoing series of C programming tutorial, I have explained many concepts related to pointers. Here in this section we will focus on some confusing pointer terminologies. We will learn and compare constant pointer with pointer to constant and constant pointer to constant.
Pointers and Array in C – relationship and use
Quick links
In C programming, pointers and array shares a very close relationship. Array is a data structure that hold finite sequential collection of similar type data. We use array to store a collection of similar type data together. To access and array element we use index. These index starts from 0 and goes up to N-1
(where N is size of the array).
Pointer to Pointer (Double Pointer) in C
In previous two posts, we learned basics of pointers. We learned to create pointers and how to perform arithmetic operations on them.
We learned to create pointers to int
and char
. In real, you can have pointer to any type in C. You can have a pointer to int
, char
, float
, double
, structure, array or even pointer. In fact, you can declare pointer to pointer to pointer to pointer. That looks complex. For now, let us focus on pointer to pointer.
Pointer arithmetic in C programming
Pointer is a variable that points to a memory location. Memory addresses are numeric value that ranges from zero to maximum memory size in bytes. These addresses can be manipulated like simple variables. You can increment, decrement, calculate or compare these addresses manually.
C language provides a set of operators to perform arithmetic and comparison of memory addresses. Pointer arithmetic and comparison in C is supported by following operators –
- Increment and decrement
++
and--
- Addition and Subtraction
+
and-
- Comparison
<
,>
,<=
,>=
,==
,!=