
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a program to understand the concept of pointers in C language?
Pointer is a variable which stores the address of other variable.
Features of Pointers
Following are the features of pointers −
Saves the memory space
Execution time is faster because of direct access to memory location.
The memory is accessed efficiently with the pointer i.e. dynamically memory is allocated and deallocated.
Pointers are used with data structures.
Here is an example for search demonstration −
We can access and print a particular character in a string by using pointers.
Following example shows how to access the elements using pointer −
Example
#include<stdio.h> int main(){ char array[5] = "Tutorial", *ptr, i, *ptr1; ptr = &array[1]; ptr1 = ptr + 3; *ptr1 = 101; for(i = 0; i < 4;i++) printf("%c", *ptr++); return 0; }
Output
In the above program, we assigned the starting value of pointer variable is with the address of second element in an array i.e) Tutorial. Then we add the value 101 i.e)'e' to the ptr variable. Thus it prints utoe.
utoe
Let us consider another example as follows −
Example
#include<stdio.h> int main(){ char string[10] = "CprogRamming", *p, i, *p1; p = &string[5]; p1 = p + 3; *p1 = 101; for(i = 0; i < 4;i++) printf("%c", *p++); return 0; }
Output
Rame
- Related Questions & Answers
- Explain the concept of pointers in C language
- Demonstrate the concept of pointers using C language
- Write a C program demonstrating examples on pointers
- Explain the concept of Sorting in C language
- Explain the concept of stack in C language
- Explain the pointers to unions in C language
- Explain the concept of pointer accessing in C language
- Explain the concept of Arithmetic operators in C language
- Explain the concept of Linked list in C language
- Explain array of pointers in C programming language
- Explain the concept of union of structures in C language
- What are the different types of pointers in C language?
- Explain the concepts of Pointers and arrays in C language
- What are pointers to structures in C language?
- Explain the concept of Uninitialized array accessing in C language