1.2编程基础之变量定义、赋值及转换(10题)
01:整型数据类型存储空间大小
#include<stdio.h> int main() { printf("%d %d\n",sizeof(int),sizeof(short)); return 0; }
02:浮点型数据类型存储空间大小
#include<stdio.h> int main() { printf("%d %d\n",sizeof(float),sizeof(double)); return 0; }
03:其他基本数据类型存储空间大小
#include<stdio.h> #include<stdbool.h> int main() { printf("%d %d\n",sizeof(bool),sizeof(char)); return 0; }
04:填空:类型转换1
#include<stdio.h> int main() { printf("D C"); return 0; }
05:填空:类型转换2
#include <iostream> using namespace std; int main() { cout<<"F E"<<endl; return 0; }
06:浮点数向零舍入
#include<stdio.h> int main() { float a; int b; scanf("%f %d\n",&a,&b); b=(int)a; printf("%d\n",b); return 0; }
07:打印ASCII码
#include <iostream> using namespace std; int main() { char x; cin >> x; cout << (int)x << endl; return 0; }
08:打印字符
#include <iostream> using namespace std; int main(){ int n; cin >> n; cout << (char)n; return 0; }
09:整型与布尔型的转换
#include<stdio.h> #include<stdbool.h> int main() { int a; bool b; scanf("%d",&a); b=a; printf("%d\n",b); return 0; }
10:Hello, World!的大小
#include<stdio.h> int main(){ int a; a=sizeof("Hello, World!"); printf("%d",a); }