How to create a pointer that cannot move to other memory address in C

1 Answer

0 votes
#include <stdio.h> 
  
int main() 
{ 
    int n = 849;
    
    int* const p = &n;
    
    *p = 3000;
    
    printf("%d\n", n);
    
    // p++; // error: increment of read-only variable ā€˜p’

    return 0;
}
  
  
  
/*
  
run:
  
3000
  
*/

 



answered Apr 3, 2024 by avibootz

Related questions

1 answer 138 views
2 answers 222 views
2 answers 244 views
1 answer 108 views
1 answer 140 views
...