Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » C programs » C pointer programs

C program to demonstrate example of array of pointers



In this C program, we are going to learn about array of pointers in C programming language, here we will learn how to declare and use an array of pointers in C?
Submitted by IncludeHelp, on April 26, 2018

In this program, we have to declare, assign and access array of pointers in C.

As we know that, pointers are the special type of variables that are used to store the address of another variable. And array is the group of similar type of variables (using single name for all variables), that takes contiguous memory locations.

"Array of pointes" is an array of the pointer variables. Here, in this C program we are declaring an array of integer pointer int *ptr[3]; it will store the address of integer variables.

C program for array of pointers



/*C program to demonstrate example of array of pointers.*/
#include <stdio.h>
 
int main()
{
    /*declare same type of variables*/
    int a,b,c;
     
    /*we can create an integer pointer array to 
  store the address of these integer variables*/
    int *ptr[3];
     
    /*assign the address of all integer variables to ptr*/
    ptr[0]= &a;
    ptr[1]= &b;
    ptr[2]= &c;
     
    /*assign the values to a,b,c*/
    a=100;
    b=200;
    c=300;
     
    /*print values using pointer variable*/
    printf("value of a: %d, b: %d, c: %d\n",*ptr[0],*ptr[1],*ptr[2]);
 
    /*add 10 to all values using pointer*/
    *ptr[0] +=10;
    *ptr[1] +=10;
    *ptr[2] +=10;
    printf("After adding 10\nvalue of a: %d, b: %d, c: %d\n",*ptr[0],*ptr[1],*ptr[2]);
 
    return 0;
}

Output

    value of a: 100, b: 200, c: 300
    After adding 10
    value of a: 110, b: 210, c: 310





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.