public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* c++ question
@ 2003-03-30  2:03 gs01han
  2003-03-31 18:13 ` Joe Buck
  0 siblings, 1 reply; 2+ messages in thread
From: gs01han @ 2003-03-30  2:03 UTC (permalink / raw)
  To: gcc

There is questions that I saw on your webpage but 
no answer on it. and i try to solve it with no success
if you sont mind can you tell me the answer?

1)
Assume that a is a C++ array containing n elements 
of type int.
a) Write a for statement that adds up all 
the element in a. Use array subscripting to access
the elements of a.
b) write a for loop using a pointer to keep track 
of the current element in a, and increment the pointer
 each time through the loop

2)
Let s be the following C++ structure:

struct s {
short a;
char b[5];
float c;
union {
  double d;
  bool e;
 long f;
};
int g;
};

I am trying to write a program that display 
how many bytes does c++ compiler allocate for
 a variable of type s ?
and what is the offset of each memeber of the 
from the beginning of the structure?(the offset
of a will be 0 for example) include the offsets 
od d, e, and f.

3)
int *create_node(int n)
{
int *p1 = new int(n);
int *p2 = new int(n);
int *p3 = p2;
int *p4 = p1;
q = p1; // q is an external variable 
return p3;
}

When create_node returns, how many of the anonymous
variables that it creates will be garbage?



thank you

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: c++ question
  2003-03-30  2:03 c++ question gs01han
@ 2003-03-31 18:13 ` Joe Buck
  0 siblings, 0 replies; 2+ messages in thread
From: Joe Buck @ 2003-03-31 18:13 UTC (permalink / raw)
  To: gs01han; +Cc: gcc

On Sat, Mar 29, 2003 at 11:43:12AM -0500, gs01han@yahoo.com wrote:
> There is questions that I saw on your webpage but 
> no answer on it. and i try to solve it with no success
> if you sont mind can you tell me the answer?

You didn't see these questions on our web page.  Your homework assignment,
perhaps?

> Assume that a is a C++ array containing n elements 
> of type int.
> a) Write a for statement that adds up all 
> the element in a. Use array subscripting to access
> the elements of a.

It will be better for you in the long run if you do your own homework,
instead of trying to get others to do it for you.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-03-31 16:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-30  2:03 c++ question gs01han
2003-03-31 18:13 ` Joe Buck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).