




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Last 4 digits of ID Write your section number:
All parts of this exam are required unless plainly and explicitly announced by the instructor during class.
Each True/False problem is to be answered T for true or F by circling the appropriate letter.
For multiple choice questions the answer(s) is to be entered by circling the label. There may be many cases with multiple correct answers.
The worth of individual problems is shown like [9].
If you have a question about a problem, write the question, the answer you are assuming, and continue.
In other words, do not ask it aloud!!
Verbosity is discouraged. We have provided sufficient lined space for answers. In some cases we may have provided more than enough. Answers should be limited to 12 words per line provided. Written answers should be written in good English. Neatness counts and we reserve the right to assign lower grades for sloppiness, much lower!
Do not remove the staple or tear exam packet apart!
Calculators, PDAs, CD players, radios, and headphones are not allowed!
K, M, G may be used. If so, K = 210 = 1024, M = 220 = 10242 , G = 230 = 10243.
Aggies do not lie, cheat, or steal and do not tolerate those who do! I have obeyed the Aggie code of honor in my answers on this exam.
Signature
Page 1 2 3 4 5 6 7 8 Total Max Pts 2 15 15 15 15 16 16 16 110 Your Points
True/False.
functions and changes can be made to the values whose pointers are passsed.
is then used as the right hand side of an assignment statement with the left hand side having been declared char ∗ left. It is legal C to access the third character of the string by left [2].
needed to store one element of array and the number of elements in array. The returned value is not of type int.
of code contaning their definition is entered.
invocation of make will not cause recompilation since this is not a real change of the source.
casting) the same value wout be output: 32 , ’ ’, and 0x
yield the same result. Because default float constant is double.
parentheses as a reference to the name of a function.
the default case.
default and enumerated cases in the code.
value of j j to zero. Causes segmentation fault on execution.
characters be input and stored in the appropriate destination.
Multiple Choice. There may be zero or multiple correct answers!!!
If the problem has more than one answer. If there are two correct answers and one is marked 2 of 3. If one is marked and a wrong one is marked 0 of 3.
a. (X)char ∗strncpy (char ∗s , const char ∗t , int n ); b. char ∗ strcat ( const char ∗s , const char ∗t ); c. (X)int strncmp( const char ∗s , const char ∗t , int n ); d. int strstr ( const char ∗s , const char ∗t );
int sum = 0, count; for (count=0; count <=8; count++) {sum+=count; if (sum==3) break;}
a. 0 b. 3 c. 4 d. (X) 2 e. the value of count is not defined after the for loop
a. the expression is evaluated without any conversion b. there is a syntax error, because double and int variables cannot be combined in one expression c. the value of type double is converted to type int before the expression is evaluated d. (X)the value of type int is converted to type double before the expression is evaluated
a. It is illegal to do arithmetic on characters. b. The result cannot be 32 since there are only 26 characters in the alphabet. c. (X)The magnitude of the result will be 32. d. (X)The result of ’A’+32 is equivalent to ’b’−1.
equivalent to added to second exam
a. (X)there may be multiple C assignments separated by commas. b. (X)this may be an empty statement. c. (X)if this is a nested for (;;) it is not recommended to assign a variable initialized in an enclosing for (;;). d. variables of type double cannot be assigned values in this portion. Can but should not
a. !y b. (x < y) || (z < y) c. (( x < y) || (z < y)) && (x < z) d. (( y < x) && (z < y)) || (x < z) Some exams have an extra left paren in item c. If so noted, give that student credit for that part.
Problems — Remember the verbosity instructions.
i n t main ( ) { char l i n e [ 6 4 ] = " Gordon Smiths Childs Barosz Janaczek " ; char ∗ t h e r e ; i n t c o u n t = 0 ; t h e r e = s t r s t r ( l i n e , " " ) ; f o r ( ; t h e r e != NULL ; c o u n t ++){ p r i n t f ( "%s\n" , t h e r e ) ; t h e r e = s t r s t r ( ++ t h e r e , " " ) ; } p r i n t f ( " count is %d\n" , c o u n t ) ; r e t u r n 0 ; }
Smiths Childs Barosz Janaczek Childs Barosz Janaczek Barosz Janaczek Janaczek count is 4
first argument: **char *** string address to output to.
second argument: **char *** conversions specifications plus
second... argument: various types, data to be converted
first argument: **char *** string address of source being searched.
second argument: **char *** string address of substring being looked for in first argument.
i n t t h e f i e l d s ( char ∗ t h e l i n e , char ∗ f i e l d s [ ] , i n t n f i e l d s ) ; i n t main ( ) { i n t f i e l d c o u n t =5 , n ; char t h e l i n e [ 1 2 0 ] , ∗ f i e l d s [ f i e l d c o u n t ] ; t h e l i n e = " 9870012 , von Eschen , Count , cve12@tamu .edu , U4 " ; n = t h e f i e l d s ( t h e l i n e , f i e l d s , f i e l d c o u n t ) ; i f ( n != f i e l d c o u n t ) { p r i n t f ( " Extraction failed , %d\n" , n ) ; e x i t ( n ) ; } r e t u r n 0 ; }
Write the function the_fields.c to perform the extraction of the fields. It will be in a separate source file. / ∗ t h e f i e l d s. c ∗ / # include # include i n t t h e f i e l d s ( char ∗ t h e l i n e , char ∗ f i e l d s [ ] , i n t n f i e l d s ) { char ∗ beginning , ∗ending ; i n t count ; b e g i n n i n g = t h e l i n e ; f o r ( count =0; count