Question

What is wrong with the following code segment, assumming it compiles correctly? char *a = "Hello";...

What is wrong with the following code segment, assumming it compiles correctly?

char *a = "Hello";

char *b = " Mom";

while( *b != '\0' ) {

*a = *b;

a++;

b++;

}

Homework Answers

Answer #1

If your code compiles correctly then it is your logical error.

Here you can not write *a = *b like this as normal variable.

As you are assigning a value of pointer b to pointer a you must write like *a == *b;

*a = *b will give you segmentation fault.

while *a == *b works correctlly.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The funciton my_strcpy(char dest, const char cource) is to copy "hello world" from source to dest....
The funciton my_strcpy(char dest, const char cource) is to copy "hello world" from source to dest. Do not use the library. The copy process will only stop at the last "\0". Make sure dest is large enough to any lenght of sentence inputted. The following is my code. The program copy the first letter of "hello world" which is "h", but the requirement is to copy the whole sentence "hello world". Thank you for your helps #include <iostream> using namespace...
What is wrong with this code? (5 pts) <html> <body> <h1> Hello world </h1> </body> <head>...
What is wrong with this code? (5 pts) <html> <body> <h1> Hello world </h1> </body> <head> <title>My First Script </title> </head> </html>
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
Show what is written by the following segment of code, given that element1, element2, and element3...
Show what is written by the following segment of code, given that element1, element2, and element3 are int variables, and queue is an object that fits the ADT of a queue. element1 = 1; element2 = 0; element3 = 4; queue.enqueue(element2); queue.enqueue(element1); queue.enqueue(element1 + element3); element2 = queue.dequeue( ); queue.enqueue(element3 * element3); queue.enqueue(element2); queue.enqueue(3); element1 = queue.dequeue( ); System.out.println(element1 + “ “ + element2 + “ “ + element3); while (!queue.isEmpty( )) {    element1 = queue.dequeue( );    System.out.println(element1)...
The following code should print X is greater than 0. However, the code has errors. Fix...
The following code should print X is greater than 0. However, the code has errors. Fix the code so that it compiles and runs correctly. (Rewrite the program with all the fixes) public class Test1 { public static void main(String[] args) { int x = 3; if (x > 0 System.out.println("x is greater than 0") else System.out.println(x is less than or equal 0"); } } Must be in java and easy to understand grade 11 course
q : explain the code for a beginner in c what each line do Question 2....
q : explain the code for a beginner in c what each line do Question 2. The following code defines an array size that sums elements of the defined array through the loop. Analyze the following code, and demonstrate the type of error if found? What we can do to make this code function correctly ? #include <stdio.h> #define A 10 int main(int argc, char** argv) { int Total = 0; int numbers[A]; for (int i=0; i < A; i++)...
what is the expected output of the following segment of code? def rec(D): → if len(D)...
what is the expected output of the following segment of code? def rec(D): → if len(D) == 0: → → return D → if len(D) == 1: → → return D → else: → → val = D.pop_back() → → rec(D).push_front(val) → → return D dq = Deque() dq.push_back('A') dq.push_back('B') dq.push_back('C') dq.push_back('D') dq.push_back('E') print(rec(dq))
(Java) For the following code segment, match the different values of the empty line with the...
(Java) For the following code segment, match the different values of the empty line with the resulting Big O complexity of the algorithm. int n = int k = 0; for (int i=0; i <= n; i++){ int j = i; while (j > 0) { // ___MISSING CODE___ k++; } } j = 0; j--; j /= 2; j = j * 2; Options for each are: O(n^3)            O(n * log n)            an...
What is the output of the following code segment? public class Exception { ... static int...
What is the output of the following code segment? public class Exception { ... static int divider(int x, int y) { try { return x/y; } catch (ArrayIndexOutOfBoundsException a) { System.out.print("A"); return 1; } } static int computer(int x, int y) { try { return divider(x,y); } catch (NullPointerException b) { System.out.print("B"); } return 2; } public static void main(String args[]){ try { int i = computer (100, 0); } catch (ArithmeticException c) { System.out.print("C"); } } } ABC A...
Hello, something I'm doing on Excel is wrong and need to know how to do this...
Hello, something I'm doing on Excel is wrong and need to know how to do this correctly on Excel, now written out. A sample of the sales at 50 Haute Dog restaurants is taken and the sample mean is $30,000 per day with a sample standard deviation of $2000. The population standard deviation is not known. a. What is the 90% confidence interval for the daily sales at all restaurants. b. What is the probability that the average sales are...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT