You are on page 1of 15

Advanced ´Cµ Programming Questions ² Folder 37123

Note: Correct answers are marked with ´ * * µ

Folder 371123

1. In the body of a program, a pointer name preceded by a(n)______________________ refers to the value to which the pointer points.
a. Index b. Subscript c. Asterisk * *

2. Which of the following refer to the F in Follow if the array contains "Follow this example?" (Select multiple answers)
A. B. C. D. one = one = one = one = stg[0] ; *stg ; *there; *stg[0]; ** ** **

3. Which of the following are true? (Select multiple answers)
a. b. c. d. Array variable names represent addresses Variables other than array variable names represent addresses Array variable names represent values Variables other than array variable names represent values **

**

4. On line 5, two integer variables are declared. Lines 6 and 7 assign values to those variables. The values are displayed by the printf( ) statement in line 8. The function is called in line 9 and two arguments are passed to it. Which of the statements below describes those arguments? 1. #include "stdio.h"
a. The value of pecans and the address of apples. * * b. The addresses of the variables pecans and apples. c. The address of pecans and the value of apples void fixup(int nuts, int *fruit); void main( ) { int pecans,apples; pecans = 100; apples = 101; printf("First values are %d d\n",pecans,apples); 9. fixup(pecans,&apples); 10. printf("Last values are %d d\n",pecans,apples); 11. } 12. void fixup(int nuts, int *fruit) 13. { 14. printf("The values are %d %d\n",nuts,*fruit); 15. nuts = 135; 16. *fruit = 172; 17. printf("The values are %d %d\n",nuts,*fruit); 2. 3. 4. 5. 6. 7. 8.

18. }

5. Could these values have been assigned to nuts and fruit by the main( ) function?
1. 2. 3. 4. 5. 6. 7. 8. #include "stdio.h" void fixup(int nuts, int *fruit); void main( ) { int pecans,apples; pecans = 100; apples = 101; printf("First values are %d d\n",pecans,apples); 9. fixup(pecans,&apples); 10. printf("Last values are %d d\n",pecans,apples); 11. } 12. void fixup(int nuts, int *fruit) 13. { 14. printf("The values are %d %d\n",nuts,*fruit); 15. nuts = 135; 16. *fruit = 172; 17. printf("The values are %d %d\n",nuts,*fruit); 18. }

A. No. B. Yes.

**

6. Which of the following are considered standard I/O functions? (Select multiple answers.)
a. b. c. d. Keyboard Printer Mouse Monitor. **

**

7. Which of the following is a conio.h function? (Select one answer)
a. getch () b. getchar() c. putch() d. putchar() **

8. Match each term on the left with its description on the right.
B C A 1. % d 2. & valin 3. I/O

A. The complementary tasks of gathering data for a computer or a program to work with, and of making the results of a computer's activities available to the user or to other computer processes. B. B. Signifies that the function expects a decimal value from the keyboard. C. A pointer to a variable which will contain the input.

9. Which of the following are true for scanf( )? (Select multiple answers)
a. It ignores leading blanks while scanning for the first data field ** b. It causes the operating system to accumulate the input characters in a buffer. * * c. The scanf( ) statement for string input specifies %s for string and names an array variable to hold the input. * * d. It uses as much memory as it needs to store the input and will overwrite whatever is in the memory that it needs; however, it will not overwrite the operating system.

10. Which one of the following lines accompanies the first line of code so that the code would read data from the array, dates, and write it to the array, appts? sprintf(appts, "%d %d %d %d (Select one answer)
a. b. c. d. %d\n",dates[0],dates[1],dates[2],dates[3],dates[4]); %d\n",appts[0],appts[1],appts[2],appts[3],appts[4]); %d\n",dates[1],dates[2],dates[3],dates[4],dates[5]); %d\n",appts[1],appts[2],appts[3],appts[4],appts[5]);

11. Why does printing from a file require two file pointers? (Select one answer)
A. One is for the file to be read, the other is for the file to be written ** B. One is for the file to be entered into memory, the other is for the file to be printed on an external printer other than a monitor.

C. Both are for the file to be read D. Both are for the file to be entered into memory 12. Which one of the following is true? (Select one answer)
A. putchar( ) output and putc( ) output go to the file indicated by the file pointer. B. putchar( ) output goes to the standard output device; putc( ) output goes to the file indicated by the file pointer C. putc( ) output goes to the standard output device; putchar( ) output goes to the file indicated by the file pointer D. putchar( ) output and putc( ) output go to the standard output device **

13. Which of the following fopen( ) statements will write to the standard DOS printer, PRN,by specifying its standard filename ? (Select one answer)
a. FILE *fp,*printer; b. putchar(c);putc(c,printer); c. printer = fopen("PRN","w"); d. fp = fopen("PRN","r"); **

14. fscanf( ) returns a value of ________________when the end of the file is reached.
a. 1; b. ²1 * * c. 0; d. Null;

15. Fill in the blank so that the code will open the file MYSTORY.TXT for reading. fp = fopen("MYSTORY.TXT"," __________");
a. b. c. d. W; P; R; * * T.

16. A file that is opened for reading must already exist. If it does not exist, the file pointer is set to _____________________.
a. b. c. d. 1; ²1; 0; null. * *

17. Why should getc( ) always test for end-of-file if it is issued with a loop? (Select one answer)
a. If it does not test for end-of-file, the loop will return more than one character at a time when reading data. b. If it does not test for end-of-file, the loop will point to NULL. c. If it does not test for end-of-file, the loop will return the value -1. d. If it does not test for end-of-file, the loop will continue reading indefinitely. **

18. What does \n at the end of a string signify? (Select one answer)
a. b. c. d. It signifies that the file pointed to by the pointer should close. It signifies a new line. ** It signifies a null character. It signifies the file pointer name.

19. Which of the following are true when coding the fopen( ) function with the "a" attribute? (Select multiple answers)
It causes coding the fopen( ) function with the "a" attribute causes data to be written at the beginning of an existing file. b. It causes coding the fopen( ) function with the "a" attribute * * causes data to be written at the end of an existing file. c. It causes coding the fopen( ) function with the "a" attribute will create a new file if one does not already exist. ** d. It causes coding the fopen( ) function with the "a" attribute will write individual characters to a file. a.

20. The __________________library function writes individual characters to a file.
a. b. c. d. PUTC( ); * * GETC( ); PRINTF( ); SCANF( ).

21. There is a #include directive for string.h as well as stdio.h for this sample program. Which function prototype in the program is described in the string.h header file? Type the name of the function. _________________________.
1. #include "stdio.h"

a. b. c. d.

FOPEN( ); STRCPY( ); * * FPRINTF( ); FCLOSE( ).

2. #include "string.h" 3. void main( ) 4. { 5. FILE *fp; 6. char stuff[25]; 7. int index; 8. fp = fopen("TENLINES.TXT","w"); 9.strcpy(stuff,"This is an example line."); 10. for (index = 1;index <= 10;index++) 11. fprintf(fp,"%s Line number %d\n",stuff,index); 12. fclose(fp); 13. }

21. In this example, where does getc(fp); put the character?
#include´stdio.h´ void main() { FILE *fp; Char c; Fp=fopen(³TENLINES.TEXT´,´r´); If (fp==Null) Printf(³File doesn¶t exist\n´); Else{ Do{ C=getc(fp); Putchar©; }while(c!=EOF); } fcolse(fp); }

A. c * * B. the Monitor C. Input Buffer D. fp

22. What happens if you do not check for end-of-file?
#includeµstdio.hµ void main() { FILE *fp; Char c; Fp=fopen(´TENLINES.TEXTµ,µrµ); If (fp==Null) Printf(´File doesn·t exist\nµ);

A. B. C. D.

The program reads forever * * The program returns an error "File does not exist" is displayed The contents of TENLINES.TXT is displayed

Else{ Do{ C=getc(fp); Putchar©; }while(c!=EOF); } fcolse(fp); }

23. Notice that the fscanf( ) function call is coded in an assignment statement, which returns a result in the variable c. If the array, oneword, contains the resulting string, what does c contain?
#include´stdio.h´ void main() { FILE *fp1; Char oneword[100]; Int c; Fp=fopen(³TENLINES.TEXT´,´r´); Do{ C=fscanf(fp1,´%s´,oneword); Printf(³%s \n´,oneword); }while(c!=EOF); fcolse(fp); }

A. B. C. D.

The number of words read * * The text to be printed The end-of-file indicator The file-type indicator

24. Assume that the first line in the file, TENLINES.TXT reads: C's the Greatest!" What is the value of c, after the first fscanf( ) executes? Type in the number.____________
a. b. c. d. 1; * * -1; 0; null.
#include´stdio.h´ void main() { FILE *fp1; Char oneword[100]; Int c; Fp=fopen(³TENLINES.TEXT´,´r´); Do{ C=fscanf(fp1,´%s´,oneword); Printf(³%s \n´,oneword); }while(c!=EOF); fcolse(fp); }

25. Match each function on the left with its description on the right.
1. scanf( ) D A. Enables data to be transferred from one to another read from memory B. Writes a line of formatted "output" to a character string in memory C. Writes a line of formatted "output" to an external device such as a monitor D. Used to get more than one character in a single function call

2. printf( ) C

3. sscanf( ) A

4. sprintf( ) B

26. Which of the following are arguments of a sprintf( ) function? (Select multiple answers)
a. Target variable ; ** b. Source variable ; ** c. The format for the data in the target variable ; ** d. The target variable as an address .

27. Which of the following are true? (Select multiple answers)
A. B. C. D. In the fgets( ) function call, the file pointer is first In the fgets( ) function call, the file pointer is last ** In the fscanf( ) function call, the file pointer is first ** In the fscanf( ) function call, the file pointer is last

28. Put the arguments of the fgets( ) function in the order in which they must appear.
Step 1:___C____ Step 2:___A____ Step 3:___B____ A. The maximum number of characters to be read B. The file pointer associated with the file C. The name of the area to receive the line

29. The if statement is the entry point for the statement block shown, but think about the exit point ... Whether the if condition is true or false, what is the exit point for this construct? (Select one answer)
A. The line following statement2 B. The line following statement 4 C. Statement 2 **
if condition is true { statement1; statement2; } else { statement3; statement4; }

30. Which of the following must be specified when using the fopen( ) function? (Select multiple answers)
A. The name of the file pointer ** B. The name of the file ** C. The kind of access required ** D. The name of the array

31. Which of the following are arguments of the fscanf( ) function? (Select multiple answers)
A. The source variable (a file pointer) ** B. The format of the data (%s) ** C. A target variable (usually a char array) ** D. EOF

32. In following program, Line 7, copies the string "This is a character string." into the array, strg and terminates it with the null character.What will the variable named one be after line 8 has executed?
#include "stdio.h" #include "string.h" void main( ) { 5. char strg[40],*there,one,two; 6. int *pt,list[100],index; 7. strcpy(strg,"This is a character string.") 8. one = strg[0];/* one and two are identical */ 9. two = *strg; 10. printf("The first output is %c %c\n",one,two); 11. one = strg[8];/* one and two are identical */ 12. two = *(strg+8); 13. printf("The second output is %c %c\n",one,two); 14. there = strg+10; 15. printf("The third output is %c\n",strg[10]); 16. printf("The fourth output is %c\n",*there); 17. for (index = 0;index < 100;index++) 18. list[index] = index + 100; 19. pt = list + 27; 20. printf("The fifth output is %d\n",list[27]); 21. printf("The sixth output is %d\n",*pt); 22.} 1. 2. 3. 4.

A. ' T ' ** B. 0 C. The address of strg D. *pt

33. After the statement in line 7, pt2 = pt1 is executed, what is the value of pt2?
1. 2. 3. 4. 5. 6. 7. 8. #include "stdio.h" void main( ) { int index,*pt1,*pt2; index = 39; pt1 = &index; pt2 = pt1; printf("Value is %d %d %d\n" index,*pt1,*pt2); 9. *pt1 = 13; 10. printf("Value is %d %d %d\n" index,*pt1,*pt2); 11. }

A. B. C. D.

&index; 39 13 52

**

34. What does line 10 display?
A. Value is 39 13 39 B. Value is 39 39 39 C. Value is 13 13 13 ** D. Value is 13 39 13
1. 2. 3. 4. 5. 6. #include "stdio.h" void main( ) { int index,*pt1,*pt2; index = 39; pt1 = &index;

7. 8.

pt2 = pt1; printf("Value is %d %d %d\n" index,*pt1,*pt2); 9. *pt1 = 13; 10. printf("Value is %d %d %d\n" index,*pt1,*pt2); 11. }

35. In the program shown, which of the assignment statements is permissible?
A. pt1 = &field1; B. All C. pt2 = &count2; D. int count2
1. 2. 3. 4. 5. 6. 7. 8. 9. #include "stdio.h" void main( ) { char field1; int index,*pt1,*pt2; int count2; pt1 = &field1; pt2 = &count2; }

**

36. Which of the following are true for pointers? (Select multiple answers)
A. It is a data item that contains the address of, or "points to," a variable that exists at a particular storage location. ** B. An ampersand preceding a variable name means that the variable is a pointer. C. An asterisk, or indirection operator, tells the compiler that the item being declared is a pointer. ** D. It contains only an address, pointing it to some entity. **

40. What will be the output of line 13? Hint: Spaces count as characters.
1. #include "stdio.h" 2. #include "string.h" 3. void main( ) 4. { 5. char strg[40],*there,one,two; 6. int *pt,list[100],index; 7. strcpy(strg,"This is a character string.") 8. one = strg[0];/* one and two are identical */ 9. two = *strg; 10. printf("The first output is %c %c\n",one,two); 11. one = strg[8];/* one and two are identical */ 12. two = *(strg+8); 13. printf("The second output is %c %c\n",one,two); 14. there = strg+10; 15. printf("The third output is %c\n",strg[10]); 16. printf("The fourth output is %c\n",*there); 17. for (index = 0;index < 100;index++) 18. list[index] = index + 100; 19. pt = list + 27; 20. printf("The fifth output is %d\n",list[27]);

A. The output is (space) (space) B. The output is a a ** C. The output is 9 9 D. The output is 8 8

21. printf("The sixth output is %d\n",*pt); 22.}

37. If line 12 were changed to the following, would the printf( ) statement still work? printf("%d",line); A._____ Yes B._____ No **
1. #include "stdio.h" 2. void main( ) 3. { 4. int numbers[5], result[5], index; 5. char line[81]; 6. numbers[0] = 74; 7. numbers[1] = 18; 8. numbers[2] = 33; 9. numbers[3] = 30; 10. numbers[4] = 97; 11. sprintf(line,"%d %d %d %d %d\n", numbers[0],numbers[1],numbers[2], numbers[3], numbers[4]); 12. 13. printf("%s",line); sscanf(line,"%d %d %d %d %d", (result),&result[1],(result+2), (result+3), &result[4]; for (index = 0;index < 5;index++) printf("The final result is %d\n",result[index]);

14. 15. 16. 17. }

38. Which one of the following is true

of the statement in Line 12?
1.#includeµstdio.hµ 2.void main( ) 3.{ 4.FILE *fp, *printer; 5.int c; 6.fp= fopen(´TENLINES.TXTµ,µrµ); 7.printer=fopen(´PRNµ,µwµ); 8. 9.do { 10.c=getc(fp); 11.if(c!=EOF){ 12.putchar(c); 13.putc(c,printer); 14.} 15.}while(c!=EOF); 16. 17.fclose(fp); 18.fclose(printer);

A. Returns a word count value B. Writes a character to the file C. Writes a character to the printer D. Writes a character to the monitor **

19.}

39. In following program, Why is &valin, as opposed to valin, used in line 7? (Select one answer)
A. Line 7 is a call to the scanf( ) function and valin is local to the main function ** B. scanf( ) only uses to the main( ) function characters and valin is an integer C. scanf( ) changes th value of the pointer, not the variable D. Line 7 is a call to the scanf( ) function, and valin is an integer
#include "stdio.h" void main( ) { int valin; printf("Input a number from 0 to 32767,stop with 100.\n"); 6. do { 7. scanf("%d",&valin); 8. printf("The value is %d\n",valin); 9. } while (valin != 100); 10. printf("End of program\n"); 11. } 1. 2. 3. 4. 5.

40. A(n) _________ is a model of a function that defines the function to the compiler and asks the compiler to perform error checking.
a. FUNCTION PROTOTYPE * * b. Array PROTOTYPE c. Macro PROTOTYPE

41. Which of the following statements is true given the portion of the program shown (Select one answer)
A. Only the pointer to the variable was passed to the function. B. The pointer to the variable was passed to the function and a new value was assigned to the variable at that address. ** C. A function pointer was declared by specifying the pointer name in parentheses and followed by the type of argument the function expects. D. Different functions were assigned to the same pointer.
findout(hours,&wage) void findout(int name,int *empno) { *empno=824; }

42. When the ___________ function is used, the operating system stores each character the user types in a buffer.
a. getchar( ) ; ** b. putchar( ); c. puts( ); d. gets( ).

43. Assume that the first line in the file, TENLINES.TXT reads: C's the Greatest!" What is the value of c, after the first fscanf( ) executes? Type in the number.

_______________
a. 1; ** b. 0; c. ²1; d. none of the above.
1.#include ´stdio.hµ 2.void main( ) 3.{ 4.FILE *fp1; 5.char oneword[100]; 6.int c; 7.fp1=fopen(´TENLINES.TXTµ,µrµ); 8.do { 9.c=fscanf(fp1,µ%sµ,oneword); 10.printf (´%s/nµ,oneword); 11.}while(c!=EOF); 12.fclose(fp1); 13.}

44. In the program shown, which of the assignment statements is permissible?
A. pt1 = &field1; B. All C. pt2 = &count2; D. int count2

**

1. 2. 3. 4. 5. 6. 7. 8. 9.

#include "stdio.h" void main( ) { char field1; int index,*pt1,*pt2; int count2; pt1 = &field1; pt2 = &count2; }

45.

What is the value of the first element of the array, list[0]?
#include "stdio.h" #include "string.h" void main( ) { char strg[40],*there,one,two; int *pt,list[100],index; strcpy(strg,"This is a character string.") 8. one = strg[0];/* one and two are identical */ 9. two = *strg; 10. printf("The first output is %c %c\n",one,two); 11. one = strg[8];/* one and two are identical */ 12. two = *(strg+8); 13. printf("The second output is %c %c\n",one,two); 14. there = strg+10; 15. printf("The third output 1. 2. 3. 4. 5. 6. 7.

a) b) c) d)

100 ** 0; 1: 101

is %c\n",strg[10]); 16. printf("The fourth output is %c\n",*there); 17. for (index = 0;index < 100;index++) 18. list[index] = index + 100; 19. pt = list + 27; 20. printf("The fifth output is %d\n",list[27]); 21. printf("The sixth output is %d\n",*pt); 22.}

46. In the programe given below, The for loop loops 100 times, assigning values to each element in the array. What is the value of the last element in the array?
#include "stdio.h" #include "string.h" void main( ) { char strg[40],*there,one,two; int *pt,list[100],index; strcpy(strg,"This is a character string.") 8. one = strg[0];/* one and two are identical */ 9. two = *strg; 10. printf("The first output is %c %c\n",one,two); 11. one = strg[8];/* one and two are identical */ 12. two = *(strg+8); 13. printf("The second output is %c %c\n",one,two); 14. there = strg+10; 15. printf("The third output is %c\n",strg[10]); 16. printf("The fourth output is %c\n",*there); 17. for (index = 0;index < 100;index++) 18. list[index] = index + 100; 19. pt = list + 27; 20. printf("The fifth output is %d\n",list[27]); 21. printf("The sixth output is %d\n",*pt); 22.} 1. 2. 3. 4. 5. 6. 7.

a. 199; ** a. 0; b. 1; d. 200.

47. A ______________ can be used to represent a queues.
a. Structures. b. Linked List. c. Arrays. **

48. A ______________ queue will have records inserted into the end of a linked list and records deleted from the head of a linked list.
a. LIFO b. FIFO. c. VIFO **

49. Two bit strings may have the operations of and, ___________ and __________ or applied to respective bits in the corresponding strings.
a. ^^ || b. inclusive, exclusive c. << >> **

50. A ______________ routine will repeatedly call itself until a criterion for terminating is satisfied.
a. Structures. b. recursive c. Sorting. **