C&C++
C&C++
Lucky@cust
这个作者很懒,什么都没留下…
展开
-
int* p[2] 与 int (*p)[2] 的不同
(1)int* p[2] 是一个指向int型的指针数组,即:p是包含两个元素的指针数组,指针指向的是int型。可以这样来用:#include <iostream.h>void main() {int* p[2];int a[3] = {1, 2, 3};int b[4] = {4, 5, 6, 7};p[0] = a;p[1] = b;for(int i = 0; i < 3; i++) cout << *p[0] + i;// cout << *转载 2021-03-18 10:18:16 · 991 阅读 · 1 评论 -
C语言中输入带空格的字符串
注:不能使用scanf("%s", p);的方式输入,可以使用gets(p);来输入。#include<stdio.h>int main(){ char q[20]; gets(q); //输入hello world printf("%s", q); //输出hello return 0;}#include<stdio.h>int main(){ char p[20]; scanf("%s", p); //输入hello world printf原创 2021-03-17 19:22:31 · 471 阅读 · 0 评论 -
字符串占用字节数与字符串长度
字符串长度(strlen)不算结尾的‘\0’;字符串所占字节数(sizeof)算结尾的‘\0’。#include<stdio.h>int main(){ printf("len=%d\n", strlen("abcdef")); //输出结果6 printf("sizeof=%d\n", sizeof("abcdef"));//输出结果7 return 0;{...原创 2021-03-17 16:12:22 · 9601 阅读 · 0 评论