In: Computer Science
(3 pts) Fill in the blanks in the following C statement such that it allocates memory for an array of 50 character values:
char *name = ( ) malloc( );
(3 pts) Write a declaration for an array a of
10 strings, each of which has at most 80 characters (including the
null character):
__________________________________________
(6 pts) Circle or underline all syntax, logic, and runtime errors found in the following C fragment. Be sure to circle omitted punctuation.
char *name_ptr == NULL, name[50] = “Barack Obama”,
*name2 = “Joe Biden”;
name_ptr = name[0];
do
{
printf (“Enter a new name: ”)
scanf (“%c”, name_ptr);
while (name == name2);
(2 pts) What are two advantages of using recursion in a C program?
__________________________________________________________________
__________________________________________________________________
(8 pts) Complete the following statements based on this declaration. Assume that the operations are cumulative:
char taste[11] = "bitter", touch[5] = "soft";
The value of strlen(taste) is . The contents of touch[4] is .
The value of strcmp(“soft”, taste) is negative/positive/zero (circle one). The contents of touch after the call strncpy(touch, taste, 3) is . The contents of taste[2] after the call strncat(taste, &touch[3], 1) is .
1) char *name=(char*)malloc(noOfCharacters*sizeof(char));
here number of characters are the length of string you want to store on heap.
2) char array[10][80];
The above declaration makes an array with 10 rows of 80 columns each.The column contains the characters in some sprecific-row string.
3)
I error: *name_ptr==NULL ....... make it *name_ptr=NULL. == is a
comparator operator and not an assignment operator.
II error: Mising open brace "{" in the do while block.
III error: name_ptr=name[0] .... make this statement as name_ptr=name;
4)
1)more simpler logic and less complex code.
2)reduce unnecessary calling of functions.
5)
strlen(taste)=6
touch[4]='\0' ... the string terminating character.
the value is negative
contents of touch is "ter"
the content of atste[2] after strcat is "f"