
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Explain the concept of pointer accessing in C language
Pointer is a variable which stores the address of other variable.
Pointer declaration, initialization and accessing
Consider the following statement −
int qty = 179;
Declaring a pointer
int *p;
‘p’ is a pointer variable that holds the address of another integer variable.
Initialization of a pointer
Address operator (&) is used to initialize a pointer variable.
int qty = 175; int *p; p= &qty;
Let’s consider an example how the pointer is useful in accessing the elements in an array of string.
In this program, we are trying to access an element which is present at particular location. The location can be found by using an operation.
By adding pre incremented pointer to pre incremented pointer string and the subtracting 32, you get the value at that location.
Example
#include<stdio.h> int main(){ char s[] = {'a', 'b', 'c', '
', 'c', '\0'}; char *p, *str, *str1; p = &s[3]; str = p; str1 = s; printf("%d", ++*p + ++*str1-32); return 0; }
Output
77
Explanation
p = &s[3]. i.e p = address of '
'; str = p; i.e str = address of p; str1 = s; str1 = address of 'a'; printf ("%d", ++*p + ++*str1 - 32); i.e printf("%d", ++
+ a -32); i.e printf("%d", 12 + 97 -32); i.e printf("%d", 12 + 65); i.e printf("%d", 77); Thus 77 is outputted
- Related Articles
- Explain the concept of pointer to pointer and void pointer in C language?
- Explain the concept of Uninitialized array accessing in C language
- Explain the concept of Array of Pointer and Pointer to Pointer in C programming
- Explain the accessing of structure variable in C language
- Explain the Random accessing files in C language
- Explain the concept of pointers in C language
- Explain the concept of Sorting in C language
- Explain the concept of stack in C language
- Explain the Union to pointer in C language
- Explain the concept of Arithmetic operators in C language
- Explain the concept of Linked list in C language
- Explain the concept of union of structures in C language
- Explain the concept of logical and assignment operator in C language
- Explain the dynamic memory allocation of pointer to structure in C language
- Explain bit field in C language by using structure concept

Advertisements