Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THANKS Question 1 Where is the storage for the \"hello\" string literal allocate

ID: 3799800 • Letter: T

Question

THANKS

Question 1

Where is the storage for the "hello" string literal allocated in memory when this program is run?

#include

int main(void) {
char * p = "hello";
printf("%s ", p);
return 0;
}

Question 1 options:

No memory is allocated to "hello".

On the heap.

Somewhere else.

On the stack.

Question 2

Where is the memory for array s allocated?

#include

int main(void) {
char s[] = "hello";
printf("%s ", s);
return 0;
}

Question 2 options:

On the stack.

Somewhere else.

On the heap.

Question 3

Is this initialization correct?

char c = "b";

Question 3 options:

Question 4  

What does the following code print?

#include

int main(void) {
char c = '0';
if (c) printf("yes ");
else   printf("no ");
return 0;
}

Question 4 options:

None of the above.

It prints "no."

It crashes.

It does not compile.

It prints "yes."

The standard does not define what the program should print.

Question 5

What does the following code print (on a 32-bit machine)?

#include

void printSize(char * p) {
printf("%zu ", sizeof(p));
}

int main(void) {
char * p = NULL;
printSize(p);
return 0;
}

Question 5 options:

It crashes.

It does not compile.

1

4

Question 6

What's the value of sizeof(char)?

Question 6 options:

8

It depends on the compiler and operating system, but it's at least 8.

1

It's either 4 on a 32-bit machine or 8 a 64-bit machine.

Question 7

What happens when you compile and run this program? (To print the return value you can use echo $? in the command-line window right after running the program.)

Question 7 options:

It returns -1.

It compiles just fine, even with -Wall -Wextra.

It produces a compilation error.

It crashes.

It produces a compilation warning, but then it returns 0.

Question 8

Consider the following program.

Does it handle the empty string input according to the specification?

Question 8 options:

Question 9

What does the following program print when executed?

Question 9 options:

4G

G

It prints nothing because it crashes when it tries to modify read-only memory.

3H

Question 10

What does the following program print when run?

Question 10 options:

That's quite a compiement!

That's quite a complement!

The program does not compile.

That's quite a compliment!

A

No memory is allocated to "hello".

B

On the heap.

C

Somewhere else.

D

On the stack.

Explanation / Answer

1. (A) No memory allocated to hello string.

2.(A) on the stack.

3. False(right one is char c='b';)

4.(E) it print yes

5.(B) it does not compile

6.(C) 1

7. (B)

8.(B) False

9. (A)

10.(B)