C / C ++指针之谜?
指针是一个变量,用于存储另一个变量的地址。指针的数据类型与变量的数据类型相同。
在这个难题中,您需要知道所使用的指针的大小。这个难题通过询问变量的大小来检验我们对指针的理解。
int的大小为4个字节,而int指针的大小为8个字节。现在,让我们通过以下c++编程语言练习来测试您的技能。
示例
#include <iostream>
using namespace std;
int main() {
int a = 6 ;
int *p = &a;
int arr[5][8][3];
int *q = &arr[0][0][0];
int ans;
cout<<"the value of a is "<<a<<endl;
cout<<"predict the size of a ";
cin>> ans;
if(ans == sizeof(p)) {
cout<<"Hurry! your prediction is right";
} else {
cout<<"Your Guess is wrong ";
}
cout<<"Now try this "<<endl;
cout<<"arr is a 3D array"<<endl;
cout<<"predict the size of arr ";
cin>> ans;
if(ans == sizeof(q)) {
cout<<"Hurry! your prediction is right";
} else {
cout<<"Your Guess is wrong ";
}
return 0;
}输出结果
the value of a is 6 predict the size of a 8 Hurry! your prediction is right Now try this arr is a 3D array predict the size of arr 4 Your guess is wrong
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下