Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Recall that Strings in C are arrays of ASCII character terminated by null character (i.e,'0' - the character with ASCII value 0). THe C library

Recall that Strings in C are arrays of ASCII character terminated by null character (i.e,'\0' - the character with ASCII value 0). THe C library function strcpy(char[] p, char[]q) copies string q to string p and is usually implemented as follows:

void strcpy(char[]a, char[]b) {

while(*a++ =*b++);

}

This code relies on C's pointer arithmetic, and has the effect of assinging the character of q into the array p until the null character that ends q is assigned to a slot in p.

a) Suppose that a C program defines three strings as follows:

char [] a1 = " Hello, world!", a2 = "Good morning, world!";

...

//code omitted

char[] a3 = "wonderful, the world!"

Assuming that a1 begins at memory location 1000, with a2 immediately following, sketch how a1 and a2 will appear in memory. Assume that each memory location takes one byte (enough for a single ASCII character).

b) Now, assuming that a3 occupies a section of memory that is different from a1 and a2 ( and distant from them), show that values of a1 and a2 after the following call.

strcpy(a1,a3);

c) What features of C does this code illustrate? How do these features affected realiability?

d) What features of JAVA and the JAVA API were desinged to address the problem illustrated above?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

How can you defend against SQL injection attacks?

Answered: 1 week ago

Question

LO6.1 Discuss price elasticity of demand and how it is calculated.

Answered: 1 week ago