All CS223 Quizzes

¡Supera tus tareas y exámenes ahora con Quizwiz!

1. #include<stdio.h> 2. void f( int a); 3. int main(void) 4. { 5. int a=10, res = 0; 6. res = f(a ); 7. printf("%d\n", a); 8. return 0; 9. } 10. void f(int a) 11. { 12. printf("%d", a); 13. a++; 14. return a; 15. }

6 or 13

T or F: Assume complete code. The following code is correct: int x = 0; scanf("%d", x);

False

T or F: The following for loop works without any errors. #include <stdio.h> int main (void) { int i, limit =500, x=0; for (i = 0; i <= limit ; i +=20 ) { x *= i; } return 0; }

True

T or F: What does the condition of the following if statement evaluates to(true or false)? Given the followings: assume complete program. yes = 3; hi = 1; by = 2; yesterday = 1; today = 0; if (((yes <= hi) && ( hi = = by)) | | (yesterday != today))

True

T or F: any loops (for, while, do-while) can be used to process an entire (every) array elements.

True

T or F: Consider array numbers below. Assume complete program. char array1 [5] = "John"; char array2 [5] = "John"; The following condition of the if statement will evaluate to true or false? if (array1 == array2)

False

Following set of code executes without any problems. Assume complete program. Line numbers are not part of the code. If no problem enter 0 as answer, if problem, enter the line number that has a problem as answer. 1. if ( temp > maxTemp) 2. { 3. printf ("turn air on \n"); 4. } 5. else ( temp <= maxTemp) 6. { 7. printf("do not touch the dial \n"); 8. }

5

How many bits are in a byte?

8

T or F: Assume complete code. The following code is correct: double area = 15.5; printf ("area is %d", area);

False

T or F: In C an (one array) array can have different data type as its elements.

False

T or F: You can have an "else" without an "if" in your program.

False

If you to use a loop for situation that you do not know how many times you need to loop but you know that the codes in the loop block needs to be executed at lease one time, what is the most appropriate loop to use? A. for loop B. do while loop C. while loop

B. do while loop

A prototype of a function looks like this: int myfunc (double x, int y, char d, int e); Which one of the following is a correct way to call this function? A. myfunc ( 1, 2, 3, 4); B. myfunc ( 1.1, 2, 'a', 2); C. myfunc ( 1, 'a', 2, 4.4); D. none of the above

B. myfunc (1.1, 2, 'a', 2);

What functions are needed to generate a random number that changes in C programming? A. rand and srand B. rand and srand and time C. time and srand D. time and rand

B. rand and srand and time

T or F: "The dark side" is a string and "charray" is an array of characters. The following line of code is correct use of strcpy function. strcpy ("The dark side", charray);

False

T or F: A function must have arguments in order to process correctly.

False

T or F: A set of if - else if statements can be replaced by a a while loop.

False

T or F: After an array is declared, the size of the array can be changed later in the program.

False

T or F: Array index can be a double data type.

False

T or F: Assume complete code, The following statement (decision making) evaluates to True or False? int x = 2, y = 4, z = 0; if ((x >= 2) || (y == 4) && ( (y- x ) < z ))

False

T or F: Compilers convert machine code into a source code.

False

T or F: Consider the following array double thisarray [10]; Following line of code is correct and does not produce any problem. Assume complete program. thisarray [10] = 3.3;

False

T or F: Following line of code correctly writes to a file without ant errors. Assume complete code and the pointer to this file has been declared. int q = 10; fprintf ( " There is %d questions in this quiz \n", q);

False

T or F: If a string is declared as in the declaration statement below, then a programmer would be able to store the string "David" in it with no unexpected problems. char str[5];

False

T or F: In C language structure is NOT a data type.

False

T or F: Members of a structure must be all of the same type of data.

False

T or F: The following code declares a constant value for the number of days in a year. #define NUM_DAYS_IN_YEAR = 365;

False

T or F: The following return statement will return a and b to the calling function. return (a , b);

False

T or F: Type of function depends on the arguments of the function.

False

T or F: A switch contract can be converted to a set of consecutive if statements (one after another).

True

T or F: An array is saved in consecutive (memory bytes) area of memory.

True

T or F: C is an interpreted programming language.

True

T or F: If myarray is an array, then myarray[i+1] is the element in the array following myarray[i].

True

T or F: String is an array of characters.

True

T or F: The expression, (iValue == iYourValue), compares the value of variable iValue to te value of variable iYourValue.

True

T or F: A for loop can always be converted to a while loop.

True

T or F: A function may be called more than one time from a block of code.

True

Functions do NOT make your program A. Modularized B. Easier to maintain C. Easier to test D. More correct

D. More correct

T or F: A member of a C language structure can be another C structure.

True

T or F: ASCII character EOF indicates the end of a text file.

True

If the string is "Dark side of the Moon", using the function strlen returns : A. 21 B. 22 C. 17 D. it returns noting

A. 21

Converting the Binary number 101011 to decimal results in: A. 43 B. 63 C. 44 D. none of the above

A. 43

What will be the output of following program ? #include <stdio.h> void main(void) { int a=1 double b=0.5, c= 0; c = a/b; switch( c ) { case 0: printf("Case ZERO\n"); break; case 1: printf("Case ONE\n"); break; case 2: printf("Case TWO\n"); break; default: printf("DEFAULT\n"); break; } } A. Compile Error B. case ONE C. case TWO D. DEFAULT E. case ZERO

A. Compile Error

Which flowchart symbol is used for decision making operation? A. Diamond B. Oval C. parallelogram D. Rectangle

A. Diamond

Which one of the followings is not a logical operator? A. && B. != C. ! D. ||

B. !=

What will be displayed by the following code? assume complete code. int x = 6, y=3, w= 7; if ( ! (( w % y ) == (w - x) ) && ( y == 3)) { printf ( " %d " , w); else { printf (" %d" , y); } A. 6 B. 3 C. 7 D. 1

B. 3

What will be the output of the below C program? #include<stdio.h> struct dist { int i; float ft; }; int main() { struct dist dec1, dec2; dec2.i = 4; decl.ft = 7.96623; printf("%d %.2f", decl.i, decl.ft); return 0; } A. 4 7.96623 B. 4 7.97 C. Compilation error D. None of the above

B. 4 7.97

Structures are MOST useful when used as: A. single variable B. Array of structures with a file with several records C. File I/O only D. All of the above

B. Array of structures with a file of several records

What data type is used to represent an exact amount of gas in your car's tank? A. Integer B. Double C. Character D. None of the above

B. Double

Which one of the followings declares a pointers to a file? A. FILE john; B. FILE *jack; C. int *FILE joe; D. pointer FILE *joe;

B. FILE *jack

What is the return type of rand( ) function? A. char B. int C. long D. double

B. int

What are the values assigned the variables a, b, c, and d by the following code? Assume complete code. int a = 0, b = 1, c = 2, d = 3; while ( (b != 0) || (d != 3) ) { if( (c ==2) && (b > 1) ) { b = b + d; a += 4; c = 5; } b = 0; } A. 0 1 2 3 B. 4 4 5 C. 0 0 2 3 D. 4 0 5 3

C. 0 0 2 3

What will be the output of the program? READ carefully #include <stdio.h> #include <math.h> double fun (double, double); int main (void) { double i = 2.0, x = 4.0; i = fun (i, x); printf("%f\n", i); return 0; } double fun(double i, double x) { double res = 0; res = pow (i , x); return ( res); } A. 2.0 B. 4.0 C. 16.0 D. 0.0

C. 16.0

Consider array numbers below , int numbers [5] = {3 , 5, 7, 9, 10}; What will be displays by the following code? Assume complete program. int counter =0; while ( numbers [counter] ! = 5) { printf( "%d " , numbers[counter]); counter += 1; } A. 3 5 7 9 10 B. 5 7 9 10 C. 3 5 D. 3 E. Nothing

C. 3 5

The following code reads from a file, what does one line of this file might looks like based on the data that it is reading ? fscanf (infile, "%s %d %d %lf %s", aa, &pr, &ty, &rr, tt) A. dark 66 66.6 77.7 strong B. John 66 66 77.7 88 C. Apple 66 66 77.7 Microsoft D. None of the above

C. Apple 66 66 77.7 Microsoft

How many times the below for loop will display "Defend The Empire" string? #include <stdio.h> main (void) { int i, total = 0; for (i=0; i<5; i--) { printf("Defend The Empire\n"); } } A. 5 B. 4 C. infinite D. none of the above

C. Infinite

Consider the prototype below, what are the parameters of the function accept? int accept (struct numbs starr[], int n); A. structure numbs and integer variable B. variable of structure numbs and integer variable C. None of the above

C. None of the above

Block of code in C is designated by: A. Open and close prentices ( ) B. Open and close square brackets [ ] C. Open and close curly braces { } D. None of the above

C. Open and close curly braces { }

Which flowchart symbol is used for I/O operation? A. Diamond B. Oval C. parallelogram D. Rectangle

C. Parallelogram

The "default" case in switch construct is: A. To prevent the program from not compiling B. To always execute, no matter what the case is C. To capture the incorrect switch parameter , switch (switch parameter) D. all the above

C. To capture the incorrect switch parameter, switch (switch parameter)

Which of the following is correct way to initialize an array in C. A. int john [3]; B. int john [3] = (1,2,3); C. int john [3] = {1,2,3}; D. none of the above

C. int john [3] = {1,2,3};

Which one of the following is NOT a proper way to name a variable in C? A. radius B. radiusOfCircle C. radius of circle D. radius_of_circle

C. radius of circle

Which of the following is a correct comment? A. 8^/ Comments 8^/ B. 8^8^ Comments 8^8^ C. 8^/ Comments /8^ D. /8^ Comments 8^/ 8^ = *

D. /* Comments */

Consider the code below, assume complete program, what will be displayed after the code executes? int counter, sum = 0, limit =5; for (counter = 0; counter < limit; counter++) { sum = sum + limit -1; } printf("%d ", sum); A. 5 B. 8 C. 12 D. 20

D. 20

What is assigned to variable W after the code below is executed? Assume complete code. int x=5, y=3, w=0, d=9; w=(y>x) ? d : y A. 5 B. 2 C. 9 D. 3

D. 3

How many times the string "Defend The Empire will be displayed by below code? #include <stdio.h> main (void) { int i = 0 , total = 0; while (total < 12) { printf("Defend The Empire\n"); total = total +3; } } A. 12 B. 11 C. 3 D. 4

D. 4

What is the output of the following program? structure hotel { int items; char name[10]; }; int main(void) { strcpy(hotel1.name,"TAJ"); hotel1.items=10; printf("%s", hotel1.name); return 0; } A. TAJ B. TAJ10 C. 10 D. Compile error

D. Compile error

Which one of the printf statements below is correct, considering the following partial code. Assume complete program. oranges = 10; weight = 1.2; totalWeight = oranges * weight; A. printf ("total weight of 10 oranges is 120 \n", oranges, totalWeight); B. printf ("total weight of %f oranges is %d \n", oranges, totalWeight); C. printf ("total weight of %d oranges is %d \n", oranges, totalWeight); D. None of the above

D. None of the above

feof is a function that A. Checks for the end of a text file B. returns false if the end of the file is not reached C. it is not the only way to check for the end of the file D. all the above

D. all the above

What are the last VALUES displayed by the following code? #include <stdio.h> int main (void) { int total = 0, i = 10, y = 3; while (total <= i) { total = total + y *3; printf (" %d %d %d\n", i, total, y); } return 0; } A. 0 10 3 B. 11 10 4 C. 10 18 3 D. none of the above

D. none of the above

assume the following structure is defined.Which one of the following declares array of structure? struct Person { // code }; A. struct Person person1; B. struct person1[5]; C. struct person[5]; D. struct person person1[5];

D. struct person person1[5];

Which of the following will evaluate to 25? a) 3 + 15%7 +7%4 b) 40/2 + 20%4 c) 100/5 +125%20 d) 5%5 - 20%5 e) None of the above

c) 100/5 +125%20

Which one of the following is not a C operator? a - % b - / c - ?: d - all are

d - all are

What value does this program print out for the value of b if the user enters 2 for the value of d? #include <stdio.h> int main (void) { int a = 4, b, d, david = -5; printf("Enter a value for d:"); scanf("%d", &d); if ((a + d + david) <= 0) { b = david + d; printf("The value of b is %d\n", b); } else { b = david + a; printf("The value of b is %d\n", b); } return 0; }

-1

ow many bytes of data the following structure will occupy in memory, after all members are initialized? struct mydata { int num1; char name [10]; double num2; char ch1; };

23

How many times the phrase "Defend the Empire" will be displayed by the following code? #include <stdio.h> int main (void) { int counter, limit =5; for (counter = 0; counter <= limit ; counter++) { printf("Defend the Empire "); } return 0; }

6

Which of the following assignment statements will get a double type variable from a user and place the value into the forth location of an array declared as my_array[12] ? A. scanf("%lf", &my_array[4]); B. scanf("%lf", &my_array[3]); C. scanf("%lf", my_array[5]); D. scanf("%lf", my_array[3]);

B. scanf("%lf", my_array[5]);

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

B. struct foo young;


Conjuntos de estudio relacionados

Cardiac Function Practice Problems

View Set

Practice with Nouns and Articles (Estructura)

View Set

Case Study 12 (Gastrointestinal Bleeding) - Prioritization, Delegation, and Assignment

View Set

Spanish II CP // Chapter 1 Test Guide

View Set