——文章由 www.owhite.cn 老白啵网站爬取得到 如有侵权请及时联系站长邮箱删除

用行指针输出二维数组元素

#include<stdio.h>
main()
int [3][4]={1,2,3,4,5,6,7,8,9,10,11,12};
int (*p)[4],i;
for(p=a;p<a+3;p++)
{
    for(i=0;i<4;i++)
    printf("%3d",*(*p+1));
    printf("\n");
}



#include<Stdio.h>
#include<string.h>
main()
{
    char*book[]={"Computer Network","Visual C++","Date Structure","Operating system","Jave"};
    int n=5;
    char *temp;
    int  i,j,k;
    for(i=0;i<n-1;i++)
    {
        k=i;
        for(j=i+1;j<n;j++)
            if(strcmp(book[i],book[j])>0) k=j;
        if(k!=i)
        {
            temp=book[i];book[k];book[k]=temp;
        }
    }
    for(i=0;i<n;i++)
        printf("%s\n",book[i]);
        return 0;
}



用指针变量作为函数参数
#include<stdio.h>
void swap(int *p,int *q)
{
    int t;
    t=*p;
    *p=*q;
    *q=t;
}
main()
{
    int a=3,b=5;
    printf("a=%d,b=%d\n",a,b);
    swap(&a,&b);
    printf("a=%d,b=%d\n",a,b);
}



返回指针的函数
#include<stdio.h>
char* GetMemory()
{
    char *p="Hi";
    return p;
}
int main()
{
    char *str=GetMemory();
    printf(str);
    return 0;
}



//1
#include<stdio.h>
int *fun1()
{
    int i=5;
    return &i;
}
int main()
{
    int *p;
    p=fun1();
    printf("%d",*p);
    return 0;
}
//2
#include<stdio.h>
int *fun1(int *q)
{
    *q=*q+5;
    return q;
}
main()
{
    int i=5,*p;
    p=fun1(&i);
    printf("%d",*p);
    return 0;
}

标签: int, includemain, a, 指针, for, 输出, 元素

评论已关闭