Question: 1) Normally variables are placed on the ( stack / heap ) by the compiler. Dynamic variables are instead placed on the ( stack /

1) Normally variables are placed on the ( stack / heap ) by the compiler. Dynamic variables are instead placed on the ( stack / heap ) by the at the programmers request. In C++ this dynamic allocation is done via the operator (or the form for a dynamically allocated array). When we are done with dynamic memory, we must release it. In C++ this is done via the operator (or its array form ).

2) Given the following code, explain what it does.

const char * mysterious(const char * s, char f, long & w)

{

const char * p = s;

while (*p != f && *p != \0)

{

p++;

}

w = (*p != \0 ? p-s : -1);

p = (*p != \0 ? p : NULL);

return p;

}

A) calculates the length of the C-string s returning this in w and a pointer to the null character in p

B) (linear) searches a C-string s for a certain character f returning (via w) the offset if found or -1

if not and the address (via p) if found or NULL if not

C) (binary) searches a C-string s for a certain character f returning (via w) the offset if found or -1

if not and the address (via p) if found or NULL if not

D) sorts the C-string s into descending or ascending order based on whether w is -1 or not

E) validates the theories espoused by various religious sects of the Disc World that no good deed goes unpun-

ished and no good punishment is truly needed most of the code is actually syntactic sugar, as such

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!