Home » C solved programs » C pointer 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.



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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





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 some rights reserved.