1. C语言提供了 short、int、long、long long 四种类型的整数,它们的长度依次递增,初学者在选择整数类型时往往比较迷惑,有时候还会导致数值溢出。
2. 下一行 using namespace std; 告诉编译器使用 std 命名空间。命名空间是 C++ 中一个相对新的概念。
3. 关于c/c++的字符、字符串的输入输出问题:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstring>
#include<string>
#include<string.h>
using namespace std;
int main()
{
//string str1 = "Hello";
//string str2 = "World";
//string str3;
char str[10];
//string str;
//int len;
scanf("%s", str);
printf("%s", str);
//cin >> str;
//cout << "shuzushi:" << str;
return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int maina()
{
//string s = "nihao";
//scanf("%s", s);
//int i;
//char s;
//scanf("%c", &s);
//scanf("%d", &i);
//printf("i的值是%d", i);
//printf("s的值是%s", s);
//char s[12];
//string s;
//scanf("%s", s);
char s[12] = "nihao";
printf("s的值是%s", s);
return 0;
}
4. 关于int int* char char*的输入输出问题
#include<stdio.h>
int main()
{
int a = 2;
//int类型的值不能用于初始化int*类型的实体
int* i;
i = &a;
printf("%d", *i);
return 0;
}
#include<stdio.h>
int main()
{
//str[12],str[]都可以
//char str[]="hello";
//char str[12] = "hello";
//不赋值的情况下,str1[]不可以
//char str1[12];
//char str1[];
//char str[7] = { 'a','b','c','d','r' };
//char类型的值不能用于初始化char*类型的实体
//char* str[6] = { 'a','b','c','d','r' };
//char str[] = "abcdr";
//const char*类型的值不能用于初始化char*,char类型的实体
//char* str = "s";
const char* str="s";
//char str = "s";
char str = 's';
//char类型的值不能用于初始化char*类型的实体
//char* str = 's';
printf("zifuchuanshi:%s", str);
return 0;
}