This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++ question


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]