Write C program to change the value of constant integer using pointers

Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
 
int main()
{
    const int a=20;     //declare and assign constant integer
    int *p;             //declare integer pointer
    p=&a;               //assign address into pointer p
 
    printf("Before changing - value of a: %d",a);
 
    //assign value using pointer
    *p=40;
 
    printf("\nAfter  changing - value of a: %d",a);
    printf("\nValue has changed.");
 
    return 0;
}

Result

Write C program to change the value of constant integer using pointers
Write C program to change the value of constant integer using pointers

Leave a Comment

x