avatar
A question about C++. Thanks.# JobHunting - 待字闺中
c*t
1
我说给我妈500,我妈说得600,那就600吧。她还有ssi,一个月800多,她也有自己的
房。 还有房租收入。 我给她钱是想让她帮忙接一下孩子送去after school,想看看大
家都给多少钱?
avatar
i*n
2
Here is my question:
class foo
{
int a;
int *b;
}
void doSth()
{
foo f;
}
void main()
{
doSth();
}
What will happen at run-time?
Thanks a lot.
avatar
x*i
3
how much is your salary?
avatar
H*7
4
这都不会,还是回去看c++ primer吧
avatar
c*t
5
普通码工收入

【在 x*******i 的大作中提到】
: how much is your salary?
avatar
l*s
6
nothing happens.
a and b are not initialized.
try this:
#include
class foo
{
private:
int a;
int *b;
public:
void print()
{
std::cout << a << std::endl;
std::cout << &a << std::endl;
std::cout << b << std::endl;
//std::cout << *b << std::endl;
}
};
void doSth()
{
foo f;
f.print();
}
void main()
{
doSth();
std::cin.get();
}

【在 i****n 的大作中提到】
: Here is my question:
: class foo
: {
: int a;
: int *b;
: }
: void doSth()
: {
: foo f;
: }

avatar
z*i
7
看来你妈被你伤心了,没指望你养老送终。

【在 c*******t 的大作中提到】
: 我说给我妈500,我妈说得600,那就600吧。她还有ssi,一个月800多,她也有自己的
: 房。 还有房租收入。 我给她钱是想让她帮忙接一下孩子送去after school,想看看大
: 家都给多少钱?

avatar
i*n
8
In my understanding, this piece of code actually does nothing except that,
the default constructor of foo will be called, a will be initialize as 0,
and b will be initialized as nullptr, and a default destructor will
eventually be called before doSth() goes out of scope. Moreover, since doSth
() is called, a function pointer will be pushed into a stack, and pop up
after doSth() goes out of scope. That is it. However, the interviewer was
not satisfied with my answer, so I am here to ask if anything missed besides
what I mentioned above.
avatar
c*t
9
我妈比我有钱,除了她自己的房子银行存款还有十几万美金呢,我是0。 我就觉得她怎
么还在乎我给的这几百

【在 z**********i 的大作中提到】
: 看来你妈被你伤心了,没指望你养老送终。
avatar
b*d
10
a,b应该不会被initialize吧。。。我印象里只有global variable会自动initialize成
0。。。

doSth
besides

【在 i****n 的大作中提到】
: In my understanding, this piece of code actually does nothing except that,
: the default constructor of foo will be called, a will be initialize as 0,
: and b will be initialized as nullptr, and a default destructor will
: eventually be called before doSth() goes out of scope. Moreover, since doSth
: () is called, a function pointer will be pushed into a stack, and pop up
: after doSth() goes out of scope. That is it. However, the interviewer was
: not satisfied with my answer, so I am here to ask if anything missed besides
: what I mentioned above.

avatar
b*c
11
孩子去after school没校车接送?

【在 c*******t 的大作中提到】
: 我说给我妈500,我妈说得600,那就600吧。她还有ssi,一个月800多,她也有自己的
: 房。 还有房租收入。 我给她钱是想让她帮忙接一下孩子送去after school,想看看大
: 家都给多少钱?

avatar
r*e
12
default constructor should initialize data members using
their corresponding default values.

【在 b*******d 的大作中提到】
: a,b应该不会被initialize吧。。。我印象里只有global variable会自动initialize成
: 0。。。
:
: doSth
: besides

avatar
c*t
13
没有

【在 b*******c 的大作中提到】
: 孩子去after school没校车接送?
avatar
m*g
14
考察参数的生存周期?
avatar
s*t
15
你也是码工的,怎么还在乎这几百?

【在 c*******t 的大作中提到】
: 我妈比我有钱,除了她自己的房子银行存款还有十几万美金呢,我是0。 我就觉得她怎
: 么还在乎我给的这几百

avatar
m*n
16
a and b are not initialized, but "a" has been allocated some memory and the
value in a's memory can be anything, not necessary to be zero. b also point
to some memory (not necessary to be nullptr) which can be anything.

doSth
besides

【在 i****n 的大作中提到】
: In my understanding, this piece of code actually does nothing except that,
: the default constructor of foo will be called, a will be initialize as 0,
: and b will be initialized as nullptr, and a default destructor will
: eventually be called before doSth() goes out of scope. Moreover, since doSth
: () is called, a function pointer will be pushed into a stack, and pop up
: after doSth() goes out of scope. That is it. However, the interviewer was
: not satisfied with my answer, so I am here to ask if anything missed besides
: what I mentioned above.

avatar
x*s
17
找个同学的妈接,一个月200够了

【在 s***t 的大作中提到】
: 你也是码工的,怎么还在乎这几百?
avatar
c*e
18
a is not initialized to 0, nor b is initialized to NULL. Try this
class foo
{
public:
// foo() {cout << a << " " << b << endl;};
int a;
int *b;
};
void doSth()
{
foo f;
cout << f.a << " " << f.b << endl;
}
int main() {
doSth();
// int a;
// cout << a << endl;
// int *b;
// cout << b << endl;
return 0;
}
avatar
c*t
19
你给你父母每月多少? 我干嘛不能在乎,我每月一分钱都攒不下来,还想给孩子存点
学费呢

【在 s***t 的大作中提到】
: 你也是码工的,怎么还在乎这几百?
avatar
c*e
20
I agree. One question, when we declare a variable without initialization,
for example "int a;" will a always be initialized as 0?

the
point

【在 m*****n 的大作中提到】
: a and b are not initialized, but "a" has been allocated some memory and the
: value in a's memory can be anything, not necessary to be zero. b also point
: to some memory (not necessary to be nullptr) which can be anything.
:
: doSth
: besides

avatar
s*t
21
靠,码工也这么穷,孩子他爹呢

【在 c*******t 的大作中提到】
: 你给你父母每月多少? 我干嘛不能在乎,我每月一分钱都攒不下来,还想给孩子存点
: 学费呢

avatar
O*o
23
没见过这么穷的码工。你一年十几万都花哪儿去了展开讲讲?

【在 c*******t 的大作中提到】
: 你给你父母每月多少? 我干嘛不能在乎,我每月一分钱都攒不下来,还想给孩子存点
: 学费呢

avatar
w*e
24

the
point
this is right.

【在 m*****n 的大作中提到】
: a and b are not initialized, but "a" has been allocated some memory and the
: value in a's memory can be anything, not necessary to be zero. b also point
: to some memory (not necessary to be nullptr) which can be anything.
:
: doSth
: besides

avatar
w*p
25

吃喝嫖赌啥不行,何必要给老妈这种不相干的人

【在 O**o 的大作中提到】
: 没见过这么穷的码工。你一年十几万都花哪儿去了展开讲讲?
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。