Question

In: Computer Science

Fill in the blanks in the following C statement such that it allocates memory for an array of 50 character values:

  1. (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(                        );

  1. (3 pts) Write a declaration for an array a of 10 strings, each of which has at most 80 characters (including the null character):

                                                 __________________________________________

  2. (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);

                 

                                                          

  1. (2 pts) What are two advantages of using recursion in a C program?

    1. __________________________________________________________________

    2. __________________________________________________________________

  2. (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                                    .



Solutions

Expert Solution

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"


Related Solutions

C++ Fill in the blanks please You are required to fill in the blanks in this...
C++ Fill in the blanks please You are required to fill in the blanks in this program. Consider that: -In main, the variables price and quantity were given the names of p (double) and q (int), respectively. -In the getData function, the parameters associated with the main variables p and q were called pp and pq, respectively. // Prototype: Do not include the names // of the variables in the prototype void getData (FILLTHEBLANK , FILLTHEBLANK); int main () {...
Fill in the blanks to rewrite the following statement: There is a positive integer that is...
Fill in the blanks to rewrite the following statement: There is a positive integer that is less than or equal to every positive integer. (a) There is a positive integer m such that m is . (b) There is a such that every positive integer. (c) There is a positive integer m which satisfies the property that given any positive integer n , m is
Fill in the blanks: Consider the following equilibrium and fill in the blanks with either increase...
Fill in the blanks: Consider the following equilibrium and fill in the blanks with either increase or decrease. I2(s) + 5F2(g) ⇌ 2IF5(g) A decrease in volume results in a Blank 1 in pressure which will Blank 2 the amount of IF5.
14.6 A- Fill in the Blanks for the required C instructions, and also fill in the...
14.6 A- Fill in the Blanks for the required C instructions, and also fill in the missing comments /******************************************************************* This program outputs 30 kHz square wave on port T, bit-0 using timer channel 0 interrupts and the output compare bit operations. *******************************************************************/ #include <mc9s12c32.h> /* derivative information */ #define HALF_P 133 /* Number clocks per 1/2 period */ /******************************************************************/ void interrupt 8 OC0_isr (void); /******************************************************************/ void main(void) {    /******************************************************************/       /* Initialize I/O */             ___________________ = 1;...
Please fill in the blanks (values of A, B, C, D, E, F, G, H, I...
Please fill in the blanks (values of A, B, C, D, E, F, G, H, I , J) for the following financial statements. The firm’s tax rate is 35.3%. Income Statement for Fiscal Year 2015 Sales 2,000 Cost of goods sold 1,500 Gross margin 500 Selling and general expenses 300 Operating income 200 Interest income 5 205 Interest expense 21 Restructuring charges 14 Income before tax 170 Income tax 60 Net income J Balance Sheet, Year 2014 and Year 2015...
C++ Memory Allocation: 1) Write a C++ program that allocates static, stack, & heap memory. Your...
C++ Memory Allocation: 1) Write a C++ program that allocates static, stack, & heap memory. Your program does not need to do anything else.  Indicate via comments where memory for at least one variable in each memory area is allocated. a) Write code that allocates static memory (only include one declaration): b) Write code that allocates stack memory (only include one declaration): c) Write code that allocates heap memory (only include one declaration): 2) Edit the C++ program below to include...
Fill in the blanks on the following table
 Fill in the blanks on the following tableE&pshareholder basisdistributiondividendreturn of capitalcapital gain20,000300,00080,000120,00010,000170,000220,000100,000170,00020,000080,000<20,000>50,000170,000
Fill in the blanks in the following Income Statement and Balance Sheet for Screven Industries. Assume...
Fill in the blanks in the following Income Statement and Balance Sheet for Screven Industries. Assume that there are 360 days in a year and that Credit Sales are 75% of total sales. Net Income is $1,200,000 Cash                            $750,000         Current Debt               ________ Acct. Rec.                   _________      L-T Debt                     ________ Inventory                    _________      Total Debt                   ________ T. Current Assets        _________      Stockholders’ Equity ________ Net Fixed Assets         _________      Total Debt and Total Assets                _________      Stockholders’ Equity ________ Total Asset Turnover                    2.5             ACP                            30 days...
Problem C. Fill True or False in the blanks for the following statements. True 1) _...
Problem C. Fill True or False in the blanks for the following statements. True 1) _ __ Operating system defines the ways in which the system resources are used to solve the computing problems of the users. 2) _ _ Operating system (OS) controls and coordinates use of hardware among various applications and users. 3) ______ System daemons are the first programs to be loaded and executed when powering-up or rebooting a computing system. 4) ______ When an OS runs...
Fill in the blanks in each of the following statements
Fill in the blanks in each of the following statementsa) --------- allows you to build JavaFx GUIS using drag and drop techniques.b) The elements in the scene graph are called --------------c) A(n) ----------- file contains the description of a JavaFX GUI.d) The method ---------------- is called by FMXLLoader before the GUI is displayed
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT