EBK DATA STRUCTURES AND ALGORITHMS IN C
EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
bartleby

Concept explainers

Question
Chapter 1, Problem 2E
Program Plan Intro

Pointers:

  • A variable whose value is another variable’s address is termed as pointer.
  • A pointer is to be declared before being used.
  • The declaration syntax for a variable that is a pointer is shown below:

    type *lvarname;

  • Here, “type is a pointer's base type and “lvarname is pointer variable’s name.
  • The asterisk sign is been used for pointer declaration.
  • The asterisk sign is being used for designation of a variable as a pointer.

Explanation of Solution

b.

Identification of errors:

Before copying “s2” to “s1”, memory has to be allocated for accommodating contents of “s1”, as shown below:

...

Explanation of Solution

c.

Identification of errors:

While memory allocation for contents of “s2” is performed, one more character has to be allocated for the end-of-string character. In the given syntax, one more character allocation is needed...

Blurred answer
Students have asked these similar questions
In C++: Examine the code segment. What will be printed? If there are any errors indicate the nature of each error. int a[7] = {31, 12, 32, 14, 25, 16, 27}; int *ptr; ptr = & a[2]; for ( i=1; i<=5; i=i+2) cout << *(ptr +i); cout << a[0] << *ptr << *ptr - 2 << *(ptr -1)) << endl;
A palindrome is a string that reads the same forwards or backwards; for example dad, mom, deed are palindromes (i.e., reversing a palindrome produces the same string).    Use C++ Programing language   Write a recursive, boolean-valued function, isPalindrome that takes a string as a parameter and returns whether the string is a palindrome.   A string, s, is a palindrome if:   s is the empty string or s consists of a single letter (which reads the same back or forward), or the first and last characters of s are the same, and the rest of the string (i.e., the second through next-to-last characters) form a palindrome. Write a test program that reads a string from the standard input device and outputs whether the input string is a palindrome or not.
Convert this into C programming. Thanks!... #include <iostream> #include<iomanip> using namespace std; int main() {       int length = 20;      for (int i = 0; i <= 120; i++) {        cout << "=";    }    cout << endl;    cout.width(10);    cout << "";      for (int i = 1; i <= 10; i++) {        cout.width(10);        cout << i;    }    cout << endl;    for (int i = 0; i <= 120; i++) {        cout << "-";    }    cout << endl;      for (int i = 1; i <= length; i++) {        cout.width(10);        cout << i << "|";        for (int j = 1; j <= 10; j++) {            cout.width(10);            cout << i * j;        }        cout << endl;    }    return 0; }
Knowledge Booster
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • The question should be done in C++, please give explanation and running result.  1. Let’s write a function that compares 2 strings and returns true if they were identical, false otherwise. The signature of this function should be: bool word_diff(std::string word1, std::string word2);  For example: std::string str1 = "Hello World";std::string str2 = "hEllO World";std::string str3 = "World";std::string str4 = "Hello World";bool result = word_diff(str1, str2); // Falsebool result = word_diff(str1, str3); // Falsebool result = word_diff(str1, str4); // True   2. Now let’s follow a classical approach to compare the content of 2 files. We should open each file, read their content word by word and compare them until a first mismatch occurs.Let’s implement a function called classical_file_diff that takes 2 arguments each of which is a file name and returns a boolean indicating whether the 2 files are identical or not. The signature of this function should be: bool…
    Please use easy logic with proper indentations and comments for understanding!. Coding should be in C++.   2. Write a recursive function that reads words from the standard input stream and displays them in reverse order on the standard output stream.  For example, if the input was: here comes the sun, the output would be: sun the comes here.  Hint: Read individual words until the end of a sentence is reached.  You can determine the end of the sentence any way you like.  Some suggestions include (a) checking the last character of a word for a sentence terminator (. ? ! )  (b) Using a keyword such as 'quit' to indicate the end of input.  (c) Using the eof method of the cin object.  (ctrl Z for windows or ctrl D for others can be used to force an end of file from the keyboard.)
    2. Write a program in C to find the length of string S1 and compare the string length with S3
    • SEE MORE QUESTIONS
    Recommended textbooks for you
  • C++ Programming: From Problem Analysis to Program...
    Computer Science
    ISBN:9781337102087
    Author:D. S. Malik
    Publisher:Cengage Learning
  • C++ Programming: From Problem Analysis to Program...
    Computer Science
    ISBN:9781337102087
    Author:D. S. Malik
    Publisher:Cengage Learning