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
Continue reading void pointer or generic pointer in C – use and arithmetic
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.
Continue reading Constant pointer and pointer to constant in C
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).
Continue reading Pointers and Array in C – relationship and use
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
char. In real, you can have pointer to any type in C. You can have a pointer to
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.
Continue reading Pointer to Pointer (Double Pointer) in C
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
- Addition and Subtraction
Continue reading Pointer arithmetic in C programming
Pointers are the heart of C programming. It is the most distinct feature of C, which provides power and flexibility to C. Pointers separates C from other programming languages.
C programmers make extensive use of pointers, because of their numerous benefits. Below are some advantages of pointers.
- Pointers are more efficient in handling arrays and structures.
- Pointers are used to return multiple values from a function.
- We use pointers to get reference of a variable or function.
- Pointer allows dynamic memory allocation (creation of variables at runtime) in C. Which undoubtedly is the biggest advantage of pointers.
- Pointers increases execution speed of program.
Continue reading Pointers in C – Declare, initialize and use
Write a C program to swap two numbers using pointers and functions. How to swap two numbers using call by reference method. Logic to swap two number using pointers in C program.
Input num1: 10
Input num2: 20
Values after swapping:
Num1 = 20
Num2 = 10
Continue reading C program to swap two numbers using call by reference
Write a C program to read two numbers from user and add them using pointers. How to find sum of two number using pointers in C programming. Program to perform arithmetic operations on number using pointers.
Input num1: 10
Input num2: 20
Sum = 30
Difference = -10
Product = 200
Quotient = 0
Continue reading C program to add two numbers using pointers
Write a C program to create, initialize and demonstrate the use of pointers. How to access values and addresses using a pointer variable in C programming.
Continue reading C program to demonstrate the use of pointers
Write a C program to input any string from user and find the first occurrence of a given character in the string. How to find the first occurrence of a given character in a string in C programming. Logic to find first occurrence of a character in a string in C programming.
Input string: I love Codeforwin.
Input character to search: o
'o' is found at index 3
Continue reading C program to find the first occurrence of a character in a string