惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
博客园_首页
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
V
Visual Studio Blog
小众软件
小众软件
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
T
Tor Project blog
Jina AI
Jina AI
GbyAI
GbyAI
C
Comments on: Blog
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
A
Arctic Wolf
有赞技术团队
有赞技术团队
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
Webroot Blog
Webroot Blog
C
Cisco Blogs
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
K
Kaspersky official blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
H
Hacker News: Front Page
D
Darknet – Hacking Tools, Hacker News & Cyber Security
D
Docker
P
Palo Alto Networks Blog
The Register - Security
The Register - Security
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志

博客园 - ________囧丶殇

django系列 - 安装和新建项目 SQL - 基础 javascript刷新父页面 SQL - 约束 C语言(8) - 反转单向链表 C语言(7) - 数据结构之单向链表 C语言(6) - 各种排序算法的比较 C语言(5) - 选择排序 快速排序 C语言(4) - 插入排序 C语言(3) - 冒泡排序 归并排序 C语言(1) - 开始之前 python实践 - 抓取网页中的图片和数据 python实践 - 下载文件 python补充(2) - 内置函数 python补充(1) python笔记(十) - 异常和文件处理 python笔记(九) - 类 part2 python笔记(八) - 类 part1 python笔记(七) - and和or
C语言(2) - 从指针开始
________囧丶殇 · 2009-05-11 · via 博客园 - ________囧丶殇

1,交换两个数:

/*
交换两个数
2009-5-11
by beango
*/void swap(float *,float *);int main(void)
{
    
float x,y;
    x 
= 1.2;
    y 
= 1.3;
    swap(
&x,&y);
    printf(
"x=%.2f; y=%.2f\n",x,y);
}
void swap(float *a,float *b)
{
    
float temp = *a;*a=*b;*= temp;
}

只要记住一点的是,这里是传值,不是传址,所以想要改变两个数的位置,当然是要改变它们的地址了,要操作地址当然是用指针了。

2,动态内存分配:

#include <stdio.h>
/*
动态内存分配
*/int main(void)
{
    
int size = 10;int *= malloc(sizeof(int)*size);
    
if(!p)
    {
        printf(
"memory error!");
        
return 0;
    }
    printf(
"memory address:%d\n",p);
    
//内存分配好了,但是还没有初始化,开始初始化数据
    int k = 0;
    
while(k<size)
        p[k
++= k;//用下标访问
    
//输出
    int i =0;
    
while(i<size && p!=NULL)//用指针访问,但是要注意边界
        printf("[%d]:%d\n",i++,*p++);
    free(p);
}

3.字符串查找

/*
字符串查找
*/int find(char **strings,char value)
{
    
char *string;
    
while(string=*strings++,*string!='\0')
    {
        
int index = 0;
        
while(*string++!='\0')
            
if(index++,*string==value)
                
return index;
        
return 0;
    }
    
return 0;
}
int main(void)
{
    
char *string1 = "abcdefg";
    
char c = 'q';
    
char **strings = &string1;
    
int index = find(strings,c);
    
if(index==0)
        printf(
"not fond!");
    
else
        printf(
"'%c' at %d of str:%s",c,index,*strings);
    
    
return 0;
}