Programming Basic--what is the output of the following code?
2008-02-26 09:05
351 查看
#include "iostream"
#include"string.h"
#include "stdio.h"
class A{
};
class A2{
char d,e;
};
struct B{
};
struct C{
char b,c;
};
struct D{
int x,y;
};
int main()
{
count<<sizeof(A)<<endl;
cout<<sizeof(A2)<<endl;
A *p1=new A();
A *p2;
A *p3;
cout<<sizeof(p1<<endl;
cout<<sizeof(p2)<<endl;
cout<<sizeof(p3)<<endl;
cout<<sizeof(B)<<endl;
cout<<sizeof(C)<<endl;
cout<<sizeof(D)<<endl;
return 0;
}
Answer:
1,2,4,1,4,1,2,8
#include"string.h"
#include "stdio.h"
class A{
};
class A2{
char d,e;
};
struct B{
};
struct C{
char b,c;
};
struct D{
int x,y;
};
int main()
{
count<<sizeof(A)<<endl;
cout<<sizeof(A2)<<endl;
A *p1=new A();
A *p2;
A *p3;
cout<<sizeof(p1<<endl;
cout<<sizeof(p2)<<endl;
cout<<sizeof(p3)<<endl;
cout<<sizeof(B)<<endl;
cout<<sizeof(C)<<endl;
cout<<sizeof(D)<<endl;
return 0;
}
Answer:
1,2,4,1,4,1,2,8
相关文章推荐
- Question 38: What is the output of the program below in C++?
- Question #49: What is the output of the program?
- [Quora] What is the most elegant line of code you've seen?
- What will the following polymorphic code output in C ++
- The following code fails when ExecMethod is called. Can anyone pinpoint what I am doing wrong?
- Fix The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 b
- What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memor
- What is the key of Data Assimilation?
- What is blocker on the road of learning English?
- What is the significance of asmlinkage modifier in C?
- Question 37: In C++, which of the following statements regarding the code below are valid?
- Given the array of digits (0 is also allowed), what is the minimal sum of two integers that are made
- ccah-500 第47题 What is the purpose of ZooKeeper in such a configuration
- ubuntu下安装VMware tools 出现What is the location of the directory of C header files that
- ccah-500 第58题 What is the cause of the error
- What is the best comment in source code you have ever encountered? [closed]
- 76 What is the effect of increasing the value of the ASM_POWER_LIMIT parameter? A. The number of DBW
- what is the mean of "GPRINT Type" in cacti
- what is new - .NET 4.5: review of the ThreadLocal
- what is the purpose of using translatable in Android strings?