char 与 int 以及一些其他的赋值方法

#include <iostream>
int main()
{
 using namespace std;
 char ch = 'M';
 int n_ch = ch;
 cout << "The ASCII code for "<< ch << " is" <<" "<< n_ch<< endl;
 cout << "Add one to the character code" << endl;
 ch = ch + 1;
 n_ch = ch;
 cout << "The ASCII code for "<< ch << " is" <<" "<< n_ch << endl;

 cout << "char is" << " " << sizeof(char) << " bytes." << endl;
 cout << "char is" << " " << sizeof(ch) << " bytes." << endl;
 cout << "int is" << " " << sizeof(int) << " bytes." << endl;
 cout << "int is" << " " << sizeof(n_ch) << " bytes." << endl;
 return 0;
 }

在这里插入图片描述

#include <iostream>
int main()
{
 using namespace std;
 int a(5);
 int b{ 6 };
 int c = { 7 };
 int d{};
 cout << a << endl<< b << endl<< c << endl<< d << endl;
 return 0;
 }

在这里插入图片描述

发布了8 篇原创文章 · 获赞 0 · 访问量 342

猜你喜欢

转载自blog.csdn.net/ipanda_huanhuan/article/details/104797980