Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,105 questions

40,777 answers

573 users

How to use const pointer to pointer in C

Learn & Practice SQL


244 views
asked Jul 28, 2017 by avibootz
retagged Aug 3, 2017 by avibootz

9 Answers

0 votes
#include <stdio.h>
  
int main(void)
{
    int n = 100;
    const int *p;
    const int **pp;
  
    pp = &p; 
    *pp = &n; 
    
    printf("n = %d\n", n);
    printf("*p = %d\n", *p);
    printf("**pp = %d\n", **pp);

    return 0;
}
  
    
/*
run:
   
n = 100
*p = 100
**pp = 100
 
*/

 





answered Jul 28, 2017 by avibootz
0 votes
#include <stdio.h>
  
int main(void)
{
    int n;
    const int *p;
    const int **pp;
  
    pp = &p; 
    *pp = &n;
    **pp = 13; // error: assignment of read-only location

    return 0;
}
  
    
/*
run:
   
 
*/

 





answered Jul 28, 2017 by avibootz
0 votes
#include <stdio.h>
  
int main(void)
{
    int n = 98;
    int *p;
    int * const *pp;
  
    pp = &p; 
    *pp = &n; // error: assignment of read-only location ā€˜*pā€™ 

    return 0;
}
  
    
/*
run:
   
 
*/

 





answered Jul 28, 2017 by avibootz
0 votes
#include <stdio.h>
  
int main(void)
{
    int n;
    int *p;
    int * const *pp;
  
    p = &n;
    pp = &p; 
    **pp = 900; 
    
    printf("n = %d\n", n);
    printf("*p = %d\n", *p);
    printf("**pp = %d\n", **pp);

    return 0;
}
  
    
/*
run:
   
n = 900
*p = 900
**pp = 900
 
*/

 





answered Jul 28, 2017 by avibootz
0 votes
#include <stdio.h>
  
int main(void)
{
    int n = 100;
    int *p;
    int ** const pp = &p; 
    
    pp = &p; // error: assignment of read-only variable 'pp'

    return 0;
}
  
    
/*
run:
   
 
*/

 





answered Jul 28, 2017 by avibootz
0 votes
#include <stdio.h>
  
int main(void)
{
    int n;
    int *p;
    int ** const pp = &p; 
    
    *pp = &n; 
    **pp = 30; 
    
    printf("n = %d\n", n);
    printf("*p = %d\n", *p);
    printf("**pp = %d\n", **pp);
  
    return 0;
}
  
    
/*
run:
  
n = 30
*p = 30
**pp = 30
 
*/

 





answered Jul 28, 2017 by avibootz
0 votes
#include <stdio.h>
  
int main(void)
{
    int n = 99;
    const int *p;
    const int * const *pp;
    
    p = &n;
    pp = &p;
    
    printf("n = %d\n", n);
    printf("*p = %d\n", *p);
    printf("**pp = %d\n", **pp);
  
    return 0;
}
  
    
/*
run:
  
n = 99
*p = 99
**pp = 99

*/

 





answered Jul 28, 2017 by avibootz
0 votes
#include <stdio.h>
  
int main(void)
{
    int n = 10;

    const int *p;
    const int ** const pp = &p; 
  
    *pp = &n; 
    
    printf("n = %d\n", n);
    printf("*p = %d\n", *p);
    printf("**pp = %d\n", **pp);
  
    return 0;
}
  
    
/*
run:
  
n = 10
*p = 10
**pp = 10

*/

 





answered Jul 28, 2017 by avibootz
0 votes
#include <stdio.h>
  
int main(void)
{
    int n;
    int *p;
    int * const * const pp = &p; 
  
    p = &n;
    
    **pp = 88; 
    
    printf("n = %d\n", n);
    printf("*p = %d\n", *p);
    printf("**pp = %d\n", **pp);
  
    return 0;
}
  
    
/*
run:
  
n = 88
*p = 88
**pp = 88

*/

 





answered Jul 28, 2017 by avibootz

Related questions

1 answer 77 views
77 views asked Jan 1, 2021 by avibootz
1 answer 21 views
1 answer 24 views
1 answer 27 views
1 answer 61 views
61 views asked May 13, 2021 by avibootz
...