Question: C++ 2. As we noted in lecture, arrays are not self-describing because the number of elements of an array is not guaranteed to be stored
C++

2. As we noted in lecture, arrays are not self-describing because the number of elements of an array is not guaranteed to be stored within the array. This implies that to traverse an array, the number of elements contained within it must be somehow supplied. In the case of character arrays (C-style strings), each is initialized with one more char- acter than it would otherwise appear to have; this is because character arrays are ter- minated by the null character \0, which has a value of zero. For example, consider the following representations 0 char bohr"Bohr"; -> 0 char michael[]-"Michael"; - With this in mind, (a) Write a function char* strdup(const char*), that copies a C-style string into memory it allocates on the free store. Do not use any standard library functions Do not use subscripting; use the dereference operator* instead. (b) Write a function char* findx (const char *s, const char *x), that finds the first occurrence of the C-style string x in s. Do not use any standard library functions. Do not use subscripting; use the dereference operator* instead (c) Write a function int strcmp(const char *s1, const char *s2) that compares C-style strings. Let it return a negative number if s1 is lexicographically before s2, zero if s1 equals s2, and a positive number if s1 is lexicographically after s2. Do not use any standard library functions
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
