CNIT 105 Final Exam

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

What number does 1111 1110 represent?

-2

What is the outcome of 8 & 2

0

What is the outcome of 5>>2 ? A. 1 B. 0 C. 10 D. 2

A. 1

What is the binary representation of -16? A. 1111 0000 B. 1110 1111 C. 1001 0000 D. 1111 0001

A. 1111 0000

What is the outcome of 12 | 3 ? A. 15 B. 12 C. 0 D. 1

A. 15

When opening a file for writing, what happens if the file does not exist? A. The file gets created. B. Results in runtime error. C. A NULL pointer will be returned.

A. The file gets created.

When invoking a function with several input parameters, the order of passing values to the function's parameters matters. A. True B. False

A. True

typedef struct { char name[20]; float price; } Object; Object toys[10]; *//Assume array is filled with values. What is the outcome of the following loop?//* for (int k = 0; k < 10; k++) { if (toys[k].price <= 15) { printf (" %s \n", toys[k].name); } } A. Will display all the toys' names that are less than or equal to $15. B. Will display the first toy in the array that is less than or equal to $15. C. Will display the last toy in the array that is less than or equal to $15.

A. Will display all the toys' names that are less than or equal to $15.

Is there anything wrong with this function? void display (int score) { int score; if (score >= 60) printf ("You passed! \n"); else printf ("You failed. \n"); } A. Yes, the function's parameter: score should not be redeclared inside the function. B. No, there is nothing wrong. C. Yes, The function should return an output.

A. Yes, the function's parameter: score should not be redeclared inside the function.

What does the function feof() return when the end of the file is reached? A. it returns true (which is 1) B. it returns the number of lines in the file. C. It returns false (which is 0) D. it returns -1

A. it returns true (which is 1)

Assume that the input file data.txt has been opened for reading using the file pointer fptr.. The file contains several whole numbers: 34 55 90 22 100 16 Which of the following will read the third value into variable number? Assume: int number; A. fscanf (fptr, "%d %d %d", &number); B. fscanf (fptr, "%d", &number); // reads the first number fscanf (fptr, "%d", &number); // reads the second number fscanf (fptr, "%d", &number); // reads the third number C. fscanf (fptr, "%d", &number);

B

typedef struct { char name[20]; float price; } Object; Object toys[10]; Assume array is filleed with values. The goal is to find the unique toy named Ninja in the array. Fill in the blank: for (int k = 0; k < 10; k++) { if (---------------------------) { printf (" Ninja was found at index: %d \n", k); break; } } A. strcpy (toys[k].name, "Ninja") B. toys[k].name == "Ninja" C. toys[k].name = "Ninja" D. strcmp(toys[k].name, "Ninja" ) == 0

D. strcmp(toys[k].name, "Ninja" ) == 0

Given the following declaration: typedef struct { int score; float gpa; } Record; Record students[10]; Assign 3.2 to the array element at index #4. A. students.gpa[4] = 3.2; B. gpa = 3.2; C. Record[4].gpa = 3.2; D. students[4].gpa = 3.2;

D. students[4].gpa = 3.2;

Strings in C are terminated with [?] character.

\0

Fill in the blanks[?] in order to fill array data with random numbers: int data[100]; for (int k = 0; k < 100; k++) { [?] = rand(); }

data[k]

Define a mask to retrieve the lowest 2 bits of a number. A. int mask = 2; B. int mask = 1<<2; C. int mask = 3;

int mask = 3;

Assume the following declaration: int num; int * ptr; Which statement will make the pointer point to variable num? A. ptr = num; B. ptr = # C. ptr -> num; D. ptr = &num;

D. ptr = &num;

What is the lowest index in array? A. Depends on the size of the array. B. 0 C. SIZE D. 1

B. 0

What will be displayed by: int data[100] = {1, 2, 3}; printf ("%d", data[3]); A. garbage B. 0 C. memory address D. 3

B. 0

What will be displayed by execution of the following program? void add (int n) { n++; } int main() { int num = 10; add (num); printf ("%d", num); return 0; } A. 12 B. 10 C. 11

B. 10

To work with a text file, which one of the following declarations is required? A. FILE ptr; B. FILE * ptr; C. File * ptr; D. file * ptr;

B. FILE * ptr;

Is the following declaration valid? int num = 100; float data[num]; A. True B. False

B. False

What will be displayed by the following? float price[5] = {20.5, 11.2, 5.5, 60, 10.7}; printf ("%d", price[5]); A. A memory loss B. Garbage - There is no index 5 in this array C. 10.7 D. 5

B. Garbage - There is no index 5 in this array

What is the scope of parameters in below function? void compute (int a, int b) { .... } A. The scope of parameters a and b is function compute and function main. B. The scope of parameters a and b is function compute. C. The scope of parameters a and b is the entire program.

B. The scope of parameters a and b is function compute.

Is there anything wrong with below code? float compute_average( int a, int b) { float answer; answer = (a + b) / 2.0; }

B. Yes, the function is not returning its output.

What is / are the parameters of the below function? float F (int a) { float b; .... } A. int B. a C. F D. a and b

B. a

Declare an array and initialize it to "Purdue University" A. int school[ ] = "Purdue University"; B. char school[ ] = "Purdue University"; C. school[ ] = "Purdue University"; D. char school[ ] = Purdue University;

B. char school[ ] = "Purdue University";

To store a social security number, ex: 111-23-2323 (including the dashes) in a C program, what would you declare? A. double ssno; B. char ssno[12]; C. char ssno; D. int ssno;

B. char ssno[12];

The text file scores.txt contains some integer numbers. It has been opened for reading using the file pointer ptr. Which statement will read the first number from the file into the variable score? Assume: int score; A. fscanf (ptr, "%d", score); B. fscanf (ptr, "%d", &score); C. fscanf ("%d", &score); D. fscanf (ptr, &score);

B. fscanf (ptr, "%d", &score);

Given the following declaration: typedef struct { int score; float gpa; } Record; Record lisa; *//Assign gpa 3.25 to lisa.//* A. Record.lisa.gpa = 3.25; B. lisa.gpa = 3.25; C. lisa = 3.25; D. gpa = 3.25;

B. lisa.gpa = 3.25;

Given: int data[100]; How many values can be stored in this array? A. 101 B. 99 C. 100

C. 100

What will be stored in n by the following: int n = 8; n = n<<1; A. 1 B. 32 C. 16 D. 4

C. 16

Define a mask to retrieve the highest bit (16th bit) in a number that can be shown in 16 bits. A. int mask = 1 << 15; B. int mask = 0X8000; C. Both A and B D. int mask = 1000 0000 0000 0000;

C. Both A and B

What is the prototype of the following function? float compute( int a, int b) { return (1/2.0) * (a + b); } A. float compute( int a, int b) ; B. float compute( int, int) ; C. Both A and B D. Compute ( int a, int b)

C. Both A and B

Given: int data[5] = {3, 6, 9, 12, 99}; What will be displayed by: printf ("%d", data); A. 3 B. All the values stored in the array will be displayed C. The memory address of data[0] D. Results in error

C. The memory address of data[0]

When should the end of the file be checked? A. When opening the file. B. When writing to the file. C. When reading from the file. D. When closing the file.

C. When reading from the file.

Declare an array and initialize it to "Robin". A. int name[ ] = "Robin"; B. char name = "Robin"; C. char name [ ] = "Robin";

C. char name [ ] = "Robin";

Which of the following declares a pointer to point to a float variable? A. float ptr; B. int * ptr; C. float * p;

C. float * p

The goal is to read a sentence into a char array. Fill in the blank. char line[80]; printf ("Enter a sentence:"); ----------------------------- A. scanf ("%s", line[ ]); B. scanf ("%s", line); C. gets(line);

C. gets(line);

Assume that a text file has been opened for reading using the file pointer: FILE * ptr; ptr = fopen ("input.txt", "r"); How would you check if the file was opened successfully? A. if (ptr == 0) // open operation failed! B. if (ptr != NULL) // open operation failed! C. if (ptr == NULL) // open operation failed! D. if (ptr = NULL) // open operation failed!

C. if (ptr == NULL) // open operation failed!

Invoke below function from main() with variables int n = 10; and float result = 0; float inverse (int num) { float ans; ans = 1.0 / num; return ans; } int main() { int n = 10; float result; --------------------------- // invoke the function printf ("Result = %f \n", result); return 0; } A. result = inverse (num); B. inverse (n); C. result = inverse (n); D. result = inverse (int n);

C. result = inverse (n);

Given: typedef struct { char shape[20]; int size; } Object; Object collection[100]; Store "Oval" in the first array element (at index 0). A. strcpy (collection[0].shape , Oval); B. collection[0].shape = "Oval"; C. strcpy ( collection[0].shape, "Oval"); D. strcpy (Object[0].shape , "Oval");

C. strcpy ( collection[0].shape, "Oval");

Store "Shannon" in the following array: char name[40]; A. name = "Shannon"; B. name[ ] = "Shannon"; C. strcpy (name, "Shannon"); D. You have to write a loop.

C. strcpy (name, "Shannon");

Invoke below function from main() with variables: float radius, height, volume; Assume that radius and height are initialized to some values. float compute (float r, float h) { float vol; vol = 3.14 * r * r * h; return vol; } A. volume = compute ( height, radius); B. volume = compute (r, h); C. volume = compute (radius, height);

C. volume = compute (radius, height);

What is the binary presentation of the hexadecimal number 7A? A. 0111 10 B. 1010 0111 C. 0111 0110 D. 0111 1010

D. 0111 1010

What will be displayed? printf("%d", 12 && 5); A. 12 B. 5 C. 4 D. 1

D. 1

Which statement will display array name to the screen? Assume: char name[10] = "Zink"; A. printf ("%s", &name); B. printf ("Zink"); C. printf ("%d", name); D. printf (%s", name);

D. printf ("%s", name);

Assume the following: int num; int * ptr; Which statement will make the pointer point to variable num? ptr = num; ptr -> num; ptr = &num

ptr = &num

If a function does not return any output, the return data type for the function should be [A].

void


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

Accounting Chapter 2 Quiz Solutions

View Set

Chapter 65: Assessment of Neurologic Function

View Set

Independent and Dependent Events

View Set

Florida Statutes, Rules, and Regulations Common to all lines

View Set