Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) In the C programming language (not C++) there is no pass by reference syntax to pass a variable by reference to a function. Instead

image text in transcribed

1) In the C programming language (not C++) there is no pass by reference syntax to pass a variable by reference to a function. Instead a variable is passed by pointer (just to be confusing, sometimes passing by pointer is called pass by reference). This lab asks you to do the same thing as C, even though normally you would just use C++'s reference parameter syntax. Here is the header for a function that takes as input a pointer to an integer: void addOne(int* ptr Num) Complete the function so it adds one to the integer referenced by ptr Num. Write a main function where an integer variable is defined, give it an initial value, call addOne, and output the variable. It should be incremented by one. 2) A palindrome is a word that is the same forwards and backwards. For example, "racecar" is a palindrome. The following program inputs a c-string (array of char) from the user. The string entered must be 14 or fewer characters because the dynamic array created is only big enough to hold 15 characters (one character is needed to store the 10 character to denote the end of the string). You can try entering a larger string - it might still work, or might not, depending upon what memory is overwritten. Complete the isPalindrome function so it returns true if the c-string passed in as a pointer is a palindrome, and false if it is not. #include #include using namespace std; bool ispalindrome(char* p, int length); int main() char* cstr = new char[15]; char c = ''; do cout > cstr; int len = strlen(cstr); cout > c; } while (C == 'y'); delete[] cstr; bool isPalindrome(char* p, int length) // Write code here to make this work. // It returns true for now just to make this compile. return true

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

The Power Of Numbers In Health Care A Students Journey In Data Analysis

Authors: Kaiden

1st Edition

8119747887, 978-8119747887

More Books

Students also viewed these Databases questions