指针数组示例_演示指针数组示例的C程序

指针数组示例

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

在此程序中,我们必须声明,分配和访问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程序中,我们声明一个整数指针数组int * ptr [3]; 它将存储整数变量的地址。

指针数组的C程序 (C program for array of pointers)

</ s> </ s> </ s>
/*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


翻译自: https://www.includehelp.com/c-programs/c-pointer-program-to-demonstrate-example-of-array-of-pointers.aspx

指针数组示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值