×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

C program to change the value of constant integer using pointers

Since, we cannot change the value of a constant but using pointer we can change it, in this program we are doing the same. Here, we have an integer constant and changing its value using pointer.

Example

/*C program to change the value of constant integer using pointers.*/

#include <stdio.h>

int main()
{   
    const int a=10;     //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=20;
     
    printf("\nAfter  changing - value of a: %d",a); 
    printf("\nWauuuu... value has changed.");
     
    return 0;
}

Output

Before changing - value of a: 10
After  changing - value of a: 20
Wauuuu... value has changed.

C Pointer Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.