先上代码:

 #include <stdio.h>
#include <string.h> const char g_ip[] = "";
int func1(const char *ip)
{
printf("ip:%s\n",ip);
printf("ip size:%d\n",sizeof(ip));
if(*ip == '\0')
printf("ip is none\n");
printf("g_ip:%s\n",g_ip);
printf("g_ip size:%d\n",sizeof(g_ip));
if(*ip == '\0')
printf("g_ip is none\n");
return ;
} int main()
{
const char ip[]="ABCDEFG";
func1(ip);
return ;
}

运行结果:

[zyc@localhost ~]$ ./a.out
ip:ABCDEFG
ip size:
g_ip:
g_ip size:

看8、9行代码,为什么ip是一个char指针, 但是%s的时候却知道到底要printf多长???

char 指针如何判断字符串需要输出长度的更多相关文章

  1. JavaScript判断字符串的字符长度(中文占两个字符)

    判断方法 //判断字符串中的字符 中文算两个字符 function chkstrlen(str) { ; ; i < str.length; i++) { ) //如果是汉字,则字符串长度加2 ...

  2. Java 判断字符串的存储长度

    判断前台输入项的长度应该都会碰到String.length()  判断出来没有超出最大长度,存到数据库就超出长度的问题,oracle字符集是gbk的不太清楚,如果是UTF-8,中文是占三个字符的,所以 ...

  3. C# 判断字符串为空(长度为0),或者是null(没有new)

    string str = null; if (string.IsNullOrWhiteSpace(str)) { MessageBox.Show("字符串为null"); } ) ...

  4. 33深入理解C指针之---通过字符串传递数据

    一.传递字符串:在函数的参数列表中,将参数声明为char指针即可实现通过字符串传递参数 1.特征: 1).字符串以char指针的形式传递,一般是const指针传递: 2).使用字符数组声明字符串,调用 ...

  5. char指针

    1.在C语言中,没有字符串类型,因此使用char指针表示字符串. 2.那么问题来了,使用char* 表示字符串,到哪里是结尾呢?因此需要一个特殊的字符作为哨兵,类似迭代器中的end(),这个哨兵就是' ...

  6. 使用if判断字符串的长度是否等于10,根据结果进行不同的输出

    string1=' print(len(string1)) # 使用len()计算字符串长度 if not len(string1) ==10: print('字符串的长度不为10') else: p ...

  7. 关于char 指针变量char *=p;这个语句的输出问题

    学习指针的时候我一直有个疑惑,请看下面的代码: #include <iostream> using std::cout; void main() { ; int *nPtr=&nu ...

  8. C语言:判断字符串是否为回文,-函数fun将单向链表结点数据域为偶数的值累加起来。-用函数指针指向要调用的函数,并进行调用。

    //函数fun功能:用函数指针指向要调用的函数,并进行调用. #include <stdio.h> double f1(double x) { return x*x; } double f ...

  9. php--------使用 isset()判断字符串长度速度比strlen()更快

    isset()速度为什么比strlen()更快呢? strlen()函数函数执行起来相当快,因为它不做任何计算,只返回在zval 结构(C的内置数据结构,用于存储PHP变量)中存储的已知字符串长度.但 ...

随机推荐

  1. Spring Batch Hello World

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11995146.html Project Directory Maven Dependency < ...

  2. 《SaltStack技术入门与实践》—— Event和Reactor系统

    Event和Reactor系统 本章节参考<SaltStack技术入门与实践>,感谢该书作者: 刘继伟.沈灿.赵舜东 Event是SaltStack里面的对每个事件的一个记录,它相比job ...

  3. 【leetcode】1124. Longest Well-Performing Interval

    题目如下: We are given hours, a list of the number of hours worked per day for a given employee. A day i ...

  4. handy源码阅读(五):PollerBase类

    使用poll内核函数等待事件发生: struct PollerBase: private noncopyable { int64_t id_; int lastActive_; PollerBase( ...

  5. Linux学习-NFS服务

    一.NFS服务相关介绍 1.NFS简介 NFS (Network File System) 网络文件系统,基于内核的文件系统.Sun公司开发,通过使用NFS,用户和程序可以像访问本地文件一样访问远端系 ...

  6. VGA驱动时序说明

    根据不同的显示器分辨率,需要不同的刷新频率. 其中显示模式中@60表示显示器1秒钟刷新60帧. 其中时钟(MHz),表示FPGA输出给显示器的时钟频率.需要我们配置PLL的时钟频率为对应频率. 其中行 ...

  7. C中的system函数

    windows操作系统下system () 函数详解(主要是在C语言中的应用) 函数名: system 功 能: 发出一个DOS命令 用 法: int system(char *command); s ...

  8. (24)Python实现递归生成或者删除一个文件目录及文件

    def removeDir(dirPath): ''' Created by Wu Yongcong 2017-8-18 :param dirPath: :return: ''' if not os. ...

  9. 网页分页page

    public class PageBean { private int page; // 第几页 private int pageSize; // 每页记录数 private int start; / ...

  10. 标签button:点击button按钮时,出现了页面自动刷新的情况

    原html: <button class="btn btn-primary" id="btnSubmit" name="btnSubmit&qu ...