C Coding Final

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

Which header file should be included to use the pow() function?

#include <math.h>

If the array myArray[a][b] is used to represent a table of rows and columns, which subscript would typically be used for the rows?

a

Which of the following functions are in the C standard math library?

cos() pow() sin()

Which of the following is not a valid function name?

my$Power

The strtok(str, chr) function modifies the original string str when the token chr is found within it.

true

Which <math.h> function rounds x to the smallest integer not less than x?

ceil(x)

Which include directive is needed to use the srand() function in a C program?

#include <stdlib.h>

What does the following snippet of code display? printf("%%%d%%", 5);

%5%

Given the following code, what are some reasonable possibilities we could use to fill in the blank? int i = 10087; int *p = &i; int *q = _________;

&i p

In the following code snippet, what symbol should replace the ?? to produce the indicated output? printf("%??d\n", 579); printf("%??d\n", -579); Desired Output: +579 -579

+

What flag in the printf() fomat control string is used to left justify the output within the specified field?

-

Arrays always start the subscript at what number?

0

f a linear search is performed against an array containing n items and is searching for the value of key that is contained in the array, what could be the smallest number of times the comparison array[j]==key would need to be performed, where j goes from 0 to (n-1) to find the value being searched for (best case scenario)?

1

Which snippet of code can be used to represent the rolling of two standard six-sided dice?

1 + rand() % 12

Which code snippet below can be used to represent rolling a standard 6-sided dice?

1 + rand() % 6

What value of a in the snippet of code below generate a random number between 10 and 100? int a = ???; int b = 100; int c = a + rand() % (b - a + 1);

10

If a bubble sort is performed on the following integer array: int myArray[] = {48, 29, 63, 11, 8, 10, 3}; What will be the value of a[2] after the first pass?

11

What is the output of the following snippet of code? int arr[] = {1, 2, 3, 4, 7, 98, 0, 12, 35, 99, 14}; printf("%d", sizeof(arr)/sizeof(arr[0]));

11

Which line in the code snippet below contains an error? 1. char buffer[1024]; 2. scanf("%s", *buffer); 3. int len = strlen(buffer); 4. printf("%s\n", buffer);

2

What number should be used in the following code snippet to store last names up to 20 characters long? char lastName[??];

21

Given the following array declaration, what is the value at the 4th subscript of the array? int numberList[]={1,2,3,4,5,6,7,8};

5

What is the value of a that is printed to the console by the following code? #include <stdio.h> void foo(int a); int main(void) { int a = 5; foo(a); printf("The value of a is: %d\n", a); return 0; } void foo(int a) { a = a + 2; return; }

5

What it the output of the following code snippet? char str[]="Hello"; printf("%d\n", strlen(str));

5

What line below will generate a compile-time error? 1. #include <stdio.h> 2. 3. void func(const int num[]) 4. { 5. num[0] = 2; 6. } 7. 8. int main(void) 9. { 10. int num[] = {0 ,1 ,2}; 11. 12. func(num); 13. 14. printf("%d\n", num[0]); 15. return 0; 15. }

5

How many total digits are displayed with the following code snippet? printf( "%6.3f", 123.123456789);

6

What is the smallest value of b that can be used in the following array declaration? char[b] = "Hello";

6

What number is printed to the console when the following program is run? #include <stdio.h> int foo(int, int); int main(void) { printf("%d\n", foo(5,7)); return 0; } int foo(int a, int b) { return (a > b) ? a : b; }

7

What is the first line of code listed that contains an error? 1. #include <stdio.h> 2. 3. int main(void) 4. { 5. char name[20]; 6. 7. printf("Enter a name: "); 8. scanf("%s", &name); 9. 10. printf("The name entered is: %s\n", name); 11. return 0; 12. }

8

If the phrase "93.5degrees" is entered on the keyboard (without the double quotes) as input to the following code snippet, what will be displayed? char str[50]; scanf("%[0123456789]", str); printf("%s", str);

93

Which of the following will return a false (zero) value from the isspace() function?

Backspace (ASCII 8)

The compiler will always store variables with the "register" storage class in a register of the CPU or cache memory.

False

If the phrase "Number727" is entered on the keyboard (without the double quotes) as input to the following code snippet, what will be displayed? char str[50]; scanf("%[^0123456789]", str); printf("%s", str);

Number

Which of the following is not a capability of the printf() function when formatting output?

Representing unsigned integers in binary format

What does the "*" represent in the following printf() statement? printf( "%*.3f", 9, 123.45678);

Specifies that a matching int argument in the arguments list is used in place of the asterisk

What is printed by the following code snippet? char character = 'A'; printf("%d", character);

The ASCII value of 'A' (65)

What symbol in a format control string of the printf() function, must be used (prefixed) to escape special symbols (such as a double quote) so the actual symbol prints?

\

Which of the following string functions is not found in the <string.h> library?

atoi()

If the array myArray[a][b] is used to represent a table of rows and columns, which subscript would typically be used for the columns?

b

Which of the following are not storage class specifiers? a) auto b) block c) register d) file e) extern f) static

b d

Which of the following is invalid for initializing a string?

char color = {'Yellow'};

Match the following conversion specifiers of the printf() function with their description.

d: display as a signed decimal integer o: display as an unsigned octal integer u: display as an unsigned decimal integer x:display as an unsigned hexadecimal integer h: placed before any integer conversion specifier to indicate a short integer l: placed before any integer conversion specifier to indicate a long integer

What does the "9" represent in the following printf() statement? printf( "%9.3f", 123.45678);

field width

Which conversion specifier when used with the percentage symbol (%) is used to print a floating-point value in either the floating-point form f or the exponential form e (or E), based on the magnitude of the value?

g

What symbol marks the beginning of each conversion specification in a format-control-string of the printf() function?

percent sign (%)

A __________ function is a function that calls itself either directly or indirectly.

recursive

Which of the following is not part of a function prototype?

the function's code

All arguments in C are passed by value.

true

The conversion specifier "%f" is used with the printf() function for displaying double values, but when using scanf() to read a double value, the conversion specifier "%lf" is used.

true

Which conversion specifier when used with the percentage symbol (%) is used to print hexadecimal integers?

x

If the input "31415" is typed on the keyboard (without the double quotes) for the following snippet of code, what is the resulting value of x and y? scanf("%3d%d", &x, &y);

x=314 y=15

Are the following three statements equivalent? int* var1; int *var1; int * var1;

yes

What is the first line of code that contains an error? 01) #include <stdio.h> 02) int myPower(int base, int exp) 03) 04) int main(void) 05) { 06) printf("%d raised to the %d power is %d\n", 2, 10, myPower(2,10)); 07) 08) return -1; 09) } 10) 11) int myPower (int base, int exp) 12) { 13) int answer = 1; 14) 15) for (int i = 1; i <= exp; i++) 16) answer = answer * base; 17) 18) return answer; 19) 20) }

02

What is the value of a printed to the console by the following code? #include <stdio.h> int foo(int a); int bar(int b); int main(void) { int a = 3; a = foo(a); printf("The value of a is: %d\n", a); return 0; } int foo(int a) { a = a + 2; return bar(a); } int bar(int a) { return a * 5; }

25

What is output value of f(a[2]) in the following code? void myFunc(int a); int main(void) { int a[] = {1,2,3,4,5,6,7,8,9,10}; myFunc( a[2] ); printf("The value of f(a[2]) is: %d\n", a[2] ); return 0; } void myFunc(int e) { e = e * 2; }

3

What is the output for the following snippet of code? enum week{Mon, Tue, Wed, Thu, Fri, Sat, Sun}; int main(void) { enum week day; day = Thu; printf("%d\n", day); ...

3

What value is printed by the following snippet of code? int a = 2, b = 4; int numberList[]={1,2,3,4,5,6,7,8}; printf("%d\n", numberList[a / b + 2]++);

3

What is the output of the following program? #include <stdio.h> int main(void) { int n = 1; { int n = 2; { auto int n = 3; printf("%d ", n); } printf("%d ", n); } printf("%d\n", n); }

3 2 1

What is the output of the following program? #include <stdio.h> int main(void) { int n = 1; { n = 2; { n = 3; printf("%d ", n); } printf("%d ", n); } printf("%d\n", n); }

3 3 3

What is output value of f(a[2]) in the following code? void myFunc(int a[], int s); int main(void) { int a[] = {1,2,3,4,5,6,7,8,9,10}; myFunc( a, 10 ); printf("The value of f(a[2]) is: %d\n", a[2] ); return 0; } void myFunc(int a[], int s) { a[2] *= 2; }

6

What is the first line of code that contains an error in the following? 1) #include <stdio.h> 2) int main() 3) { 4) int a = 10; 5) int *aPtr = &a; 6) aPtr = 20; 7) printf("The dereference of aPtr is: %d\n", *aPtr); 8) return 0; 9) }

6

If a bubble sort is performed on the following integer array: int myArray[] = {48, 29, 63, 11, 8, 10, 3}; What will be the value of a[6] after the 3rd pass?

63

What is the output of the following snippet of code? #include enum month {Jan, Feb=5, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec}; int main(void) { enum month name; name = Jun; printf("%d\n", name);

9

What value is output by the following code snippet? int number[] = {1,2,3,4,5,6,7,8,9,10}; int value; value = ++number[1 + 2 * 3]; printf("The name entered is: %d\n", value);

9

Which snippet of code will produce a random number between 95 and 105 inclusive?

95 + rand() % 11

Which C Library is required to use the getchar() function?

<stdio.h>

To compile without warnings or errors, what library header should be included when using the C library rand() function?

<stdlib.h>

Which include directive needs to be used for the rand() and srand() functions?

<stdlib.h>

Which statement regarding the strlen() function in the following code snippet is false? char myString[] = "Is this easy?"; printf("%d\n", strlen(myString) );

Requires the <stdio.h> header to function.

Which statement best describes the following code snippet? char str[5]="Winter is coming"; printf("%d\n", strlen(str));

The code will compile, and C will allow the extra characters to overwrite sections of memory.

Which of the following is the lowest access privelege for a pointer and the data it points to? a) Constant pointer to constant data b) Non-constant pointer to constant data c) Constant pointer to non-constant data d) Non-constant pointer to non-constant data

a

Which operator has the highest precedence? a) * (unary) b) * (multiplicative) c) == (equality) d) *= (assignment)

a

Which statement is true? a) The address operator (&) is an unary operator and the indirection operator (*) is an unary operator. b) The address operator (&) is NOT an unary operator and the indirection operator (*) is an unary operator. c) The address operator (&) is an unary operator and the indirection operator (*) is NOT an unary operator. d) The address operator (&) is NOT an unary operator and the indirection operator (*) is NOT an unary operator.

a

Which variable from the code snippet below is responsible for shifting the value (i.e,. the first number in the desired range of the consecutive integers) of the random number being generated? int a,b,n; n = a + rand() % b;

a

Which of the following are types of scope that an identifier can have? a) file b) block c) register d) function e) extern f) static

a b d

Which of the following are valid array names? a) float array[10]; b) int long[10]; c) char money_int[10]; d) int 4cost[10]; e) int freq2run[10]; Correct!

a c e

Which variable from the code snippet below is responsible for scaling the value (i.e,. determining the desired range of the consecutive integers) of the random number being generated? int a,b,n; n = a + rand() % b;

b

What is the scope of the variable a in the following program? #include <stdio.h> int cube(int n); int b = 10; int main(void) { int a = 10; printf("%d\n", cube(a)); } int cube(int x) { int y = x * x * x; return y; }

block scope

What is the scope of the variable x in the following program? #include <stdio.h> int cube(int n); int b = 10; int main(void) { int a = 10; printf("%d\n", cube(a)); } int cube(int x) { int y = x * x * x; return y; }

block scope

Given the following declaration of variables, which statement is true? int* a1, a2; a) a1 is an integer type, a2 is an integer type b) a1 is is an integer type, a2 is a pointer to an integer type c) a1 is a pointer to an integer type, a2 is an integer type d) a1 is a pointer to an integer type, a2 is a pointer to an integer type

c

Match the following functions from <string.h> with their descriptions.

char *strcpy( char *s1, const char *s2 ) copies string s2 into array s1. the value of s1 is returned. char *strcat( char *s1, const char *s2 ) appends string s2 to array s1. the first character of s2 overwrites the termination null character of s1. the value... int strcmp( const char *s1, const char *s2 ); compares the string s1 with the string s2, the function returns 0, less than 0, less than 0 or greater than 0 if s1 is equal to,... char *strrchr( const char *s, int c ); locates the last occurence of c in string s. if c is found, a pointer to c in string s is returned. otherwise a NULL... char *strchr( const char *s, int c ); locates the first occurence of character c in string s. if c is found, a pointer to c in s is returned otherwise, a... char *strpbrk( const char *s1, const char *s2 ); locates the first occurence in string s1 of any character in string s2. if a character from string s2 is from string s2 is found, a...

Which of the following assignments is/are invalid? a) myArray[2] = 10; b) myArray[2 + 3] = 5; c) myArray[6 / 4] = 15; d) myArray[4.0 / 2] = 20; f) myArray[10 % 2] = 15;

d

Which of the following is the highest access privilege for a pointer and the data it points to? a) Constant pointer to constant data b) Non-constant pointer to constant data c) Constant pointer to non-constant data d) Non-constant pointer to non-constant data

d

In the following chunk of code, if we want to execute the line y = &x, what should be the data type for y? double x = 3.14; _____ y; y = &x;

double *

Match the following string conversion functions to their description.

double strtod( const char *nPtr, char **endPtr ); converts the string nPtr to double long strtol( const char *nPtr, char **endPtr, int base ); converts the string nPtr to long unsigned long strtoul( const char *nPtr, char **endPtr, int base ); converts the string nPtr to unsigned long int atoi( const char *nPtr ); converts the string nPtr to an integer

A C program can only use functions from the standard library or user-defined functions but not both in the same program.

false

If an array is declared of size 10 as follows, name[10], then the array bounds checking of the C programming language will prevent a program from referring to an element that does not exit such as the 12th element.

false

Is the following code valid for all compilers? char *str = "Book"; str[0]='L';

false

Only iteration can result in an infinite loop. Recursion can never result in an infinite loop since recursion since it has a base case.

false

The size of a double variable is always guaranteed to be 8 bytes.

false

The strncpy(s1,s2,5) function call will always copy the NULL terminator of of s2 to s1.

false

The strtok(STR, CHR) will tokenize a string STR that contains many of the tokens identified by CHR, will tokenize the entire string with the first call to strtok().

false

Which function is used to read an entire line of text until a newline or end-of-file character is encountered?

fgets()

Which of the following streams is not automatically connected when program execution begins?

file output stream

What is the scope of the variable b in the following program? #include <stdio.h> int cube(int n); int b = 10; int main(void) { int a = 10; printf("%d\n", cube(a)); } int cube(int x) { int y = x * x * x; return y; }

file scope

Which <math.h> function rounds x to the largest integer not greater than x?

floor(x)

What is the scope of the identifier here on line 10 of the program below? 1) #include <stdio.h> 2) 3) int main(void) 4) { 5) int a = 5; 6) // Don't write code like this! 7) goto here; 8) a = a * 2; 9) 10) here: 11) a = a * 3; 12) 13) printf("Value of a: %d\n", a); 14) }

function scope

Which is the only type of scope that can be assigned to a label?

function scope

What is the scope of the variable n in the following program? #include <stdio.h> int cube(int n); int b = 10; int main(void) { int a = 10; printf("%d\n", cube(a)); } int cube(int x) { int y = x * x * x; return y; }

function-prototype scope

Modules in C are called ______________.

functions

What should be placed in the blank so that bPtr can be used to modify the value of the variable a? int a = 10; int *aPtr; ___ bPtr; aPtr = &a; bPtr = &aPtr; **bPtr = 15;

int **

Match the following functions from <ctype.h> with their descriptions.

int isalpha(int c); Returns a true value if c is a letter and 0 otherwise. int isalnum(int c); Returns a true value if c is a digit or a letter and 0 otherwise. int isprint(int c); Returns a true value if c is a printing character including a space and return 0 otherwise. int isgraph(int c); Returns a true value if c is a printing characterother than space and returns 0 otherwise. int isdigit(int c); Returns a true vale if c is a digit and 0 (false) otherwise. int ispunct(int c); Returns a true value if c is a printing character other than a space, a digit, or a letter and returns 0 otherwise.

Match the words with their definitions. (Textbook program example).

mean: arithmetic average of a set of values median: "middle value" in a sorted set of values mode: value that occurs most frequently in a set of numbers

If a linear search is performed against an array containing n items and is looking for the value of key, how many times must the comparison array[j]==key be made if the key is not to be found in the array where j goes from 0 to (n-1)?

n times

Which output would be reasonable for the following code snippet? char str[] = "Hello"; printf("%c ", str[4]); printf("%s ", str); printf("%p\n", str);

o Hello 0x7ffe99be308a

How many words will be stored into the array buffer[] when the following input is typed on the keyboard for the code snippet listed? Keyboard Input: This is a sentence of six words. char buffer[1024]; scanf("%s" , buffer);

one

What C function is used to seed the random number generator?

srand()

Can a main() be a recursive function, that is to say can main() call itself?

true

Can the C programming language be used to with 3-dimensional and higher order arrays? int array1[10][5][2]; int array2[10][5][2][12];

true

Given a sorted list of integers stored in an array, a binary search will always do less work than a linear search when the value being searched for is not in the array.

true

In the C programming language, all arguments to functions are pass by value, and not pass by reference.

true

In the C programming language, arrays are stored in contiguous memory locations.

true

Is the following code snippet valid syntax? int array[5]; array[0] = 1; array[1] = 'A'; printf("%d\n", array[0]); printf("%d\n", array[1]);

true

Is the following function prototype valid, that is to say, does it contains valid syntax? double foo(int a , int);

true

Iteration and recursion can occur infinitely: An infinite loop occurs with iteration if the loop continuation test never becomes false; infinite recursion occurs if the recursion step does not reduce the problem in a manner that converges on the base case.

true

Iteration and recursion each involve a termination test: Iteration terminates when the loop-continuation condition fails; recursion terminates when a base case is recognized.

true

The strcat(s1,s2) function call starts overwriting s1 with the characters of s2 at the terminating null character of s1.

true

char string1[] = "Hello"; char string2[] = {'H', 'e', 'l', 'l', 'o', '\0' }; Does string1 contain the same value as string2?

true


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

Chapter 10: Fluid and Electrolytes

View Set

Y10 Lit Revision (AIC, L&R, J&H)

View Set

Anatomy: Vasculature and Innervation of the Heart

View Set

M9 - Chapter 14 (The Insurance Contract)

View Set