KEY PT1 PRF192

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

D

11 ^ 5 What does the operation shown above produce? A. 1 B. 6 C. 8 D. 14 E. 15

B

4. What punctuation ends most lines of C code? A. . B. ; C. : D. '

C

After the sample code below has been executed, what value will the variable x contain? int x = 5; int y = 2; char op = '*'; switch (op) { default : x += 1; case '+' : x += y; case '-' : x -= y; } A. 4 B. 5 C. 6 D. 7 E. 8

A

Before you can read or write to a file in C, what do you need to do? A. Call fopen on the file B. Create the file C. Call fclose on the file D. Use fprintf

B

C is which kind of language? A. Machine B. Procedural C. Assembly D. Object-oriented E. Strictly-typed

A

CPU memory is volatile - the contents of the registers are lost as soon as power is turned off. A. TRUE B. FALSE

C

Consider the code below int i, x=0; for(i=1; i<10; ++i) { if(i%2==1) x=x+i; else x--; } printf("%d",x); A. 23 B. 1 C. 21 D. 19 E. 20

A

Consider the code below int i; int total = 0; int keepreading = 1; for(i=1;i<10&&keepreading==1; i++) if(!(i%3)) keepreading=0; else total+=i; printf("%d",total); A. 3 B. 1 C. 2 D. 6

B

Consider the code below int[] = {1, 4, 8, 5, 1, 4}; int *ptr,y; ptr = x+4; y=ptr-x; What does y in the code above equal? A.1 B. 4 C. 5 D. -3 E. 0

A

Evaluate !(1 && !(0 || 1)). A. True B. False C. Unevaluatable

A

For which value(s) of the integer x will the following code become an infinite loop? int number=1; while(1) { printf("%d ",number); if (number == 3) break; number += x; } A. only 0 B. only 1 C. only 2 D. only 1 or 2

A

How do you open a file for binary IO? A. Use the "b" flag to fopen B. Files are opened for binary IO by default C. Use fread and fwrite D. You need to use a special file type, BINARYFILE*

A

How do you write a string of text into a file? A. Open file and use fprintf. B. Open a file and use printf, the output will go to the file instead of the screen. C. Open a file, and use fputc repeatedly. D. Use fread to read data into the file.

C

How long does the following code run? for(int x=0; x<=2; x++) A. none B. twice C. thrice D. forever

C

How many times is a do while loop guaranteed to loop? A. 0 B. Infinitely C. 1 D. Variable

A

If you didn't do as well as you like, be sure to read through Cprogramming.com's tutorial on Switch..Case. Otherwise, congratulations! 1. Which follows the case statement? A. : B. ; C. - D. A newline

C

Predict the output from: printf("%d, %f\n", 5/-2, 5/-2.); A. -3, -2.500000 B. -2, -2.000000 C. -2, -2.500000 D. a compiler or run time error

D

Select the statement which will EXACTLY reproduce the line of text below: "My salary was increased by 15%!" A. printf("\"My salary was increased by 15/%\!\"\n"); B. printf("My salary was increased by 15%!\n"); C. printf("My salary was increased by 15'%'!\n"); D. printf("\"My salary was increased by 15%%!\"\n"); E. printf("\"My salary was increased by 15'%'!\"\n");

C

What character ends all strings? A. '.' B. ' ' C. '\0' D. '\n'

A

What does the following code fragment print? int x=0; while(++x<3) printf("%d",x); A. 1 2 B. 2 3 C. 1 2 3 D. 0 1 2

A

What flag do you need to pass to fopen to append to an existing file instead of recreating the file? A. a B. r C. w D. W+

D

What is a difference between a declaration and a definition of a variable? a). Both can occur multiple times, but a declaration must occur first. b). There is no difference between them c). A definition occurs once, but a declaration may occur many times. d). A declaration occurs once, but a definition may occur many times.

B

What is required to avoid falling through from one case to the next? A. end; B. break; C. Stop; D. A semicolon.

C

What is the correct value to return to the operating system upon the successful completion of a program? A. -1 B. 1 C. 0 D. Programs do not return a value

C

What is the correct value to return to the operating system upon the successful completion of a program? A. -1 B. 1 C. 0 D. Programs do not return a value.

A

What is the final value of x when the code int x; for(x=0; x<10; x++) {} A. 10 B. 9 C. 0 D. 1

A

What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run? A. 10 B. 9 C. 0 D. 1

A

What is the header file containing getch() function? A. conio B. stdlib C. stdio.h D. all of the above

B

What is the index number of the last element of an array with 29 elements? A. 29 B. 28 C. 0 D. Programmer-defined

C

What is the only function all C programs must contain? A. start() B. system() C. main() D. program()

C

What is the only function all C programs must contain? A. start() B. system() C. main() D. program()

A

What is the output when th sample code below is executed? int i; i=1; i=i+2*i++; printf("%d"); A. 4 B. 1 C. 2 D. 3

D

What is the output when the sample code below is executed? int calculate(int c) { c=c+15; if(c>=45) return(10); else return(10*10); } int main() { int a=20, b; b=calculate(a); printf("%d %d", a, b); return(0); } A. 45 100 B. 45 10 C. 20 10 D. 20 100 E. Compiler error

D

What is the result of the following code? int x=0; switch(x) { case 1: printf( "One" ); case 0: printf( "Zero" ); case 2: printf( "Hello World" ); } A. One B. Zero C. Hello World D. ZeroHello World

C

What is the return type of the function foo(with prototype) below: int foo(char x, loat v, double t); A. char B. int C. float D. double

B

What is the return type of the function with prototype: "int func(char x, float v, double t);" A. char B. int C. float D. double

C

What keyword covers unhandled possibilities? A. all B. contingency C. default D. other

C

What number will z in the sample code above contain? int z,x=5,y=-10,a=4,b=2; z = x++ - --y * b / a; A. 5 B. 6 C. 10 D. 11 E. 12

A

What object do you use to represent a file in C? A. FILE* B. fopen C. printf D. fprintf

A

What punctuation is used to signal the beginning and end of code blocks? A. { } B. -> and <- C. BEGIN and END D. ( and )

B

What value will x contain in the sample code above? int x = 2 * 3 + 4 * 5; A. 22 B. 26 C. 46 D. 50 E. 70

C

What will be the output of the following code fragment? The input is as follows: int x=11; printf("%d %o %x", x, x, x); A. 11 b 13 B. 11 15 b C. 11 13 b D. 11 b 15

D

What will print when the sample code above is executed? char* myFunc (char *ptr) { ptr += 3; return (ptr); } int main() { char *x, *y; x = "HELLO"; y = myFunc (x); printf ("y = %s \n", y); return 0; } A. y = HELLO B. y = ELLO C. y = LLO D. y = LO E. x = O

D

What will the above sample code produce when executed? void myFunc (int x) { if (x > 0) myFunc(--x); printf("%d, ", x); } int main() { myFunc(5); return 0; } A. 1, 2, 3, 4, 5, 5, B. 4, 3, 2, 1, 0, 0, C. 5, 4, 3, 2, 1, 0, D. 0, 0, 1, 2, 3, 4, E. 0, 1, 2, 3, 4, 5,

A

When does the code block following while(x<100) execute? A. When x is less than one hundred B. When x is greater than one hundred C. When x is equal to one hundred D. While it wishes

A

When does the code block following while(x<100) execute? A. When x is less than one hundred B. When x is greater than one hundred C. When x is equal to one hundred D. While it wishes

D

Which conversion is not possible? A. int to float B. float to int C. char to float D. All are possible

D

Which conversion is not possible? A. int to float B. float to int C. char to float D. All are possible

D

Which header file do you need to include to use typecasting? A. stdin.h B. ctype.h C. math.h D. None

A

Which is a good use for typecasting? A. To allow division of two integers to return a decimal value. B. To allow your program to use nothing but integers. C. To change the return type of a function. D. To swap variables rapidly.

A

Which is a good use for typecasting? A. To allow division of two integers to return a decimal value. đúng B. To allow your program to use nothing but integers. C. To change the return type of a function. D. To swap variables rapidly

C

Which is a valid typecast? A. a(char); B. char:a; C. (char)a; D. to(char, a);

D

Which is not a loop structure in C? A. for B. do while C. while D. repeat until

D

Which is not a loop structure? A. for B. do while C. while D. repeat until

B

Which is not a proper prototype? A. int funct(char x, char y); B. double funct(char x) C. void funct(); D. char x();

B

Which is not a proper prototype? A. int funct(char x, char y); B. double funct(char x) C. void funct(); D. charx();

B

Which line has all reserved words? Select one: A. sizeof, const, typedef, static, voided, enum, struct, union B. if, else, for, while do, switch, continue, break C. char, int, float, doubleld, short, longm unsigned, signed D. defaulted, goto, return, extern, private, public, protected

A

Which loop that counts from 0 to 5 A. for (c = 0; c <= 5; c++) B. for (int c = 0; c <= 6; c++) C. for (c = 0; c < 5; c++) D. for (c = 0; c <= 4; c++)

A

Which of the following accesses a variable in a pointer to a structure, *b? A. b->var; B. b.var; C. b-var; D. b>var;

B

Which of the following accesses a variable in structure b? A. b->var; B. b.var; C. b-var; D. b>var;

C

Which of the following adds one string to the end of another? A. append(); B. stringadd(); C. strcat(); D. stradd();

A

Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements? A. foo[6]; B. foo[7]; C. foo(7); D. foo;

A

Which of the following correctly declares an array? A. int anarray[10]; B. int anarray; C. anarray{10}; D. array anarray[10];

D

Which of the following functions compares two strings? A. compare(); B. stringcompare(); C. cmp(); D. strcmp();

A

Which of the following gives the memory address of a variable pointed to by pointer a? A. a; B. *a; C. &a; D. address(a);

C

Which of the following gives the memory address of integer variable a? A. *a; B. a; C. &a; D. address(a);

B

Which of the following gives the memory address of the first element in array foo, an array with 100 elements? A. foo[0]; B. foo; C. &foo; D. foo[1];

C

Which of the following gives the value stored at the address pointed to by pointer a? A. a; B. val(a); C. *a; D. &a;

B

Which of the following is a complete function? A. int funct(); B. int funct(int x) {return x=x+1;} C. void funct(int) {printf( "Hello" ); D. void funct(x) {printf( "Hello" ); }

C

Which of the following is a correct comment? A. */ Comments */ B. ** Comment ** C. /* Comment */ D. { Comment }

D

Which of the following is a correct comment? A. */ Comments */ B. ** Comment ** C. { Comment } D. /* Comment */

D

Which of the following is a properly defined struct? A. struct {int a;} B. struct a_struct {int a;} C. struct a_struct int a; D. struct a_struct {int a;};

B

Which of the following is a string literal? A. Static String B. "Static String" C. 'Static String' D. char string[100];

B

Which of the following is a two-dimensional array? A. array anarray[20][20]; B. int anarray[20][20]; C. int array[20, 20]; D. char array[20];

C

Which of the following is a valid function call (assuming the function exists)? A. funct; B. funct x, y; C. funct(); D. int funct();

B

Which of the following is not a correct variable type? A. float B. real C. int D. double

B

Which of the following is not a correct variable type? A. float B. real C. int D. double

B

Which of the following is the boolean operator for logical-and? A. & B. && C. | D. |&

D

Which of the following is the correct operator to compare two variables? A. := B. = C. equal D. ==

D

Which of the following is the correct operator to compare two variables? A. := B. = C. equal D. ==

A

Which of the following is the correct way to increment the variable "ptr"? void *ptr; myStruct myArray[10]; ptr = myArray; A. ptr = ptr + sizeof(myStruct); B. ++(int*)ptr; C. ptr = ptr + sizeof(myArray); D. increment(ptr); E. ptr = ptr + sizeof(ptr);

D

Which of the following is the proper declaration of a pointer? A. int x; B. int &x; C. ptr x; D. int *x;

B

Which of the following is the proper keyword or function to allocate memory in C? A. new B. malloc C. create D. value

A

Which of the following is the proper keyword or function to deallocate memory? A. free B. delete C. clear D. remove

E

Which of the following is true? A. 1 B. 66 C. .1 D. -1 E. All of the above

A

Which of the following reads in a string named x with one hundred characters? A fgets(x, 101, stdin); B. fgets(x, 100, stdin); C. readline(x, 100, '\n'); D. read(x);

C

Which of the following shows the correct syntax for an if statement? A. if expression B. if { expression C. if ( expression ) D. expression if

C

Which of the following shows the correct syntax for an if statement? A. if expression B. if{ expression C. if( expression ) D. expression if

A

Which of the following statement would create a random number in the range of [1, 10] (inclusive) ? A. 1+ rand( )%10 B. rand( )%10 C. 1+ rand( )%11 D. rand( )%11

B. Understandability C. Modifiablity

Which of the following statements are true about maintainability in good software engineering? (select all correct answers) A. A program is small enough in size B. Understandability C. Modifiablity D. A program can run on any computer E. All of the above

B. The 0 prefix identifies the number as an octal number C. Each octal digit represents 3 bits of information E. Octal number system has 8 digits, 0-7

Which of the following statements are true about octal number representaion? A. Each octal digit represents 2 bits of information B. The 0 prefix identifies the number as an octal number C. Each octal digit represents 3 bits of information D. The oc prefix identifies the number as an octal number E. Octal number system has 8 digits, 0-7

C

Which of the following statements is true? A. The execution unit (EU) executes the instructions two at a time B. The execution unit (EU) executes the instructions three at a time C. The execution unit (EU) executes the instructions one at a time D. The execution unit (EU) executes many instructions at a time

E

Which one of the following functions is the correct choice for moving blocks of binary data that are of arbitrary size and position in memory? A. memcpy() B. memset() C. strncpy() D. strcpy() E. memmove()

A

Which one of the following statements will properly initialize the variable t with the current time from the sample above? time_t t; A. t = clock(); B. time( &t ); C. t = ctime(); D. t = localtime(); E. None of the above

B

Which properly declares a variable of struct foo? A. struct foo; B. struct foo var; C. foo; D. int foo;

C

Why can typecasting be dangerous? A. Some conversions are not defined, such as char to int. B. You might permanently change the value of the variable. C. You might temporarily lose part of the data - such as truncating a float when typecasting to an int. D. There are no dangers.

E

With every use of a memory allocation function, what function should be used to release allocated memory which is no longer needed? A. unalloc() B. dropmem() C. dealloc() D. release() E. free()

E

int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; What value does testarray[2][1][0] in the sample code above contain? A. 3 B. 5 C. 7 D. 9 E. 11

D

referring to the sample below what is max_num? # define max_num 15 A. MAX_NUM is an integer variable. B. MAX_NUM is a linker constant. C. MAX_NUM is a precompiler constant. D. MAX_NUM is a preprocessor macro. E. MAX_NUM is an integer constant.

E

what will be the output when following code is executed int a=10,b; b=a++ + ++a; printf("%d,%d,%d,%d",b,a++,a,++a); A. 12,10,11,13 B. 22,10,11,13 C. 22,11,11,11 D. 12,11,11,11 E. 22,13,13,13


संबंधित स्टडी सेट्स

BUSINESS COMMUNICATION CARDON CH 9

View Set

Principles of Advertising CH. 9 Planning Media Strategy: Disseminating the Message

View Set

Biology: Quiz 2: BODY FRAMEWORK AND REPRODUCTION

View Set

FINAL FUNDAMENTALS (masterpiece)

View Set

Presidents: # 16 Abraham Lincoln, Rep., 1861-1865

View Set