
- 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
Demonstrate the concept of pointers using C language
The pointer is a variable that stores the address of another variable.
The syntax for the pointer is as follows −
pointer = &variable;
Example
Following is the C program for the concept of pointers using C language −
#include<stdio.h> void main(){ //Declaring variables and pointer// int a=2; int *p; //Declaring relation between variable and pointer// p=&a; //Printing required example statements// printf("Size of the integer is %d
",sizeof (int));//4// printf("Address of %d is %d
",a,p);//Address value// printf("Value of %d is %d
",a,*p);//2// printf("Value of next address location of %d is %d
",a,*(p+1));//Garbage value from (p+1) address// printf("Address of next address location of %d is %d
",a,(p+1));//Address value +4// //Typecasting the pointer// //Initializing and declaring character data type// //a=2 = 00000000 00000000 00000000 00000010// char *p0; p0=(char*)p; //Printing required statements// printf("Size of the character is %d
",sizeof(char));//1// printf("Address of %d is %d
",a,p0);//Address Value(p)// printf("Value of %d is %d
",a,*p0);//First byte of value a - 2// printf("Value of next address location of %d is %d
",a,*(p0+1));//Second byte of value a - 0// printf("Address of next address location of %d is %d
",a,(p0+1));//Address value(p)+1// }
Output
When the above program is executed, it produces the following result −
Size of the integer is 4 Address of 2 is 6422028 Value of 2 is 2 Value of next address location of 2 is 463824 Address of next address location of 2 is 6422032 Size of the character is 1 Address of 2 is 6422028 Value of 2 is 2 Value of next address location of 2 is 0 Address of next address location of 2 is 6422029
- Related Articles
- Explain the concept of pointers in C language
- Write a program to understand the concept of pointers in C language?
- Explain Arithmetic operations using pointers in C language?
- How to calculate sum of array elements using pointers in C language?
- Explain array of pointers in C programming language
- Explain the pointers to unions in C language
- Explain the concept of Sorting in C language
- Explain the concept of stack in C language
- What are the different types of pointers in C language?
- Explain the concepts of Pointers and arrays in C language
- Find the largest number in a series by using pointers in C language
- Explain the concept of one and two dimensional array processing using 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

Advertisements