C 程序 指针变量

来源:这里教程网 时间:2026-02-16 13:04:30 作者:

在本教程中,我们将编写一个 C 程序来创建,初始化和访问指针变量。

示例:用于创建,访问和初始化指针的程序

在下面的程序中,我们声明了一个字符变量ch和字符指针pCh,之后我们用 char ch的地址值初始化了指针变量pCh。

该示例还说明了如何使用指针变量pCh访问ch的值和地址。

/* Created by Chaitanya for Beginnersbook.com * C program to create, initialize and access a pointer */#include <stdio.h>int main(){    //char variable    char ch;    //char pointer    char *pCh;    /* Initializing pointer variable with the     * address of variable ch     */    pCh = &ch;    //Assigning value to the variable ch    ch = 'A';    //access value and address of ch using variable ch    printf("Value of ch: %c\n",ch);    printf("Address of ch: %p\n",&ch);    //access value and address of ch using pointer variable pCh    printf("Value of ch: %c\n",*pCh);    printf("Address of ch: %p",pCh);   return 0;}

输出:

C 程序 创建,初始化和访问指针变量

相关 C 示例

    C 程序:检查闰年C 程序:交换两个数字C 程序:查找int,float,double和char的大小C 程序:查找字符的 ASCII 值

相关推荐