C++指针操作举例

C++指针操作举例,具体代码如下:

 

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void funcpp(char ** p)
{
    char *tmp;
    tmp = malloc(sizeof(char) * 10);
    sprintf(tmp,"%.08d",1);
    *p = tmp;
}
void funcValue(char p)
{
    printf("funcValue=%c\n",p);
    p = 'M';
}
 
void funcp(char *p)
{
    p = "mary";
    printf("in funcp=%s\n",p);
}
int main(int argc,char *argv[])
{
   /* int nc = 1;
    nc++;
    char strnc[8];
    sprintf(strnc,"%08d",nc);
    printf("the formatted ncstr is %s\n",strnc);
    */
    char *p = "hunter";
    funcValue(*p);
    printf("after funcValue %s\n",p);
    funcp(p);
    printf("after funcp %s\n",p);
    funcpp(&p);
    printf("after funcpp %s\n",p);
    free(p);
}
output:
funcValue=h
after funcValue hunter
in funcp=mary
after funcp hunter
after funcpp 00000001
posted @ 2013-07-18 11:00  bytjj  阅读(156)  评论(0编辑  收藏  举报