CS1121_Spring_2011_MIdterm2_Sample_Questions.BB

CS1121_Spring_2011_MIdterm2_Sample_Questions.BB - Midterm2...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Midterm2 Review Sample Questions What is the output of the following program: #include <stdio.h> int main () { int nn = 5,k; //printf("How many numbers? "); //scanf("%d",&nn); printf("Here is a Table of %d Numbers\n",nn); int *ntable = (int *) calloc (nn,sizeof(int)); for (k=0; k<nn;k++) ntable[k] = k * k; for (k=0; k<nn;k++) printf("ntable ( %d ) = %d \n",k,ntable[k]); free (ntable); return 0; } Sample Questions What is the output of the following program: #include <stdio.h> int main () { int nn = 5,k; //printf("How many numbers? "); //scanf("%d",&nn); printf("Here is a Table of %d Numbers\n",nn); int *ntable = (int *) calloc (nn,sizeof(int)); for (k=0; k<nn;k++) ntable[k] = k * k; for (k=0; k<nn;k++) printf("ntable ( %d ) = %d \n",k,ntable[k]); free (ntable); return 0; } ./a.out Here is a Table o ntable ( 0 ) = 0 ntable ( 1 ) = 1 ntable ( 2 ) = 4 ntable ( 3 ) = 9 ntable ( 4 ) = 16 ntable ( 5 ) = 25 ntable ( 6 ) = 36 Sample Questions What is displayed by the following code fragment? #include <stdio.h> main () { char pres = "Adams, John Quincy" ,temp1[40], temp2[40]; strncpy(temp1, &pres[7], 4); temp1[4] = '\0'; strcat(temp1," "); strncpy(temp2, pres, 5); temp2[5] = '\0'; printf("%s\n",strcat(temp1,temp2)); return 0 Sample Questions What is displayed by the following code fragment? #include <stdio.h> main () { char pres = "Adams, John Quincy" ,temp1[40], temp2[40]; strncpy(temp1, &pres[7], 4); temp1[4] = '\0'; strcat(temp1," "); strncpy(temp2, pres, 5); temp2[5] = '\0'; printf("%s\n",strcat(temp1,temp2)); return 0 $ ./a.out John Adams Sample Questions Consider the following valid call: printf(“%s\n”,strs[4]); Which of the following statements are true?...
View Full Document

This note was uploaded on 11/14/2011 for the course CSCI 1121 taught by Professor Haya during the Fall '11 term at GWU.

Page1 / 25

CS1121_Spring_2011_MIdterm2_Sample_Questions.BB - Midterm2...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online