CIT 330 WKU Final

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/49

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

50 Terms

1
New cards

How many times is the loop body of the while statement executed?

int g = 0;

int s = 0;

int z = 0;

int i = 0;

while (i <=5){

scanf("%d", &t);

s = s+ t;

if (t >= 0);

g = g + 1;

else

z = z + 1;

i = i + 1;

}

6 times

2
New cards

How many times will the following loop iterate?

int j = 1;

while (j>5){

printf("%d", j);

}

No iterations

3
New cards

Which loop is specifically designed to initialize, test, and increment a counter variable?

for loop

4
New cards

Which of the following statement is true about the statement below?

int score [5] = {83, 92, 78, 94, 71};

This is an array declaration and initialization.

5
New cards

Suppose a program contains the code

for (i = 1; i < = 10; i++){

n[i] = 1;

}

It is initializing successive elements in an array.

6
New cards

What is the subscript index for the data value 92 in the example given below?

int score [5] = {83, 92, 78, 94, 71}

one

7
New cards

What will be the output of this program fragment?

char u, v, temp; u = 'a'; v = 'b'

while (v != 'a'){

temp = u;

u = v;

v = temp;

}

printf("%c %c", u, v);

ba

8
New cards

What is the output of the following program?

#include

void bing(int n){

printf("%4d", n);

}

int main(void){

double x;

x = 41;

bing(x);

printf("%.2f\n", x);

return (0);

}

41 41.10

9
New cards

What will be the output of this program fragment?

int value = 0;

do{

printf("%d", value);

value = value + 2;

}

while (value <5);

024

10
New cards

How many of the parameters are considered input parameters in the function below?

voidapart(double x, int wholep, double fracp){

*wholep = (int)x;

fracp = x - wholep;

}

1

11
New cards

Which of the following is optional when writing a function definition?

return statement

12
New cards

Which of the following code segments does not contain any errors?

double triple(float n){

return (3 * n);

}

13
New cards

What will be the output of this program fragment?

int value = 1;

do{

printf("%d\n", value);

value = value + 2;

}

while (value <5);

1

3

14
New cards

The function prototype

double mySqrt(int x);

defines a function called mySqrt which takes an integer as an argument and returns a double.

15
New cards

What is the output of the following program fragment?

double x[8] = {16.0, 12.0, 6.0, 8.0, 2.5, 12.0, 12.0, -54.5};

int j = 5;

printf("%.2f\t", x[j] + 1);

printf("%.2f\t", x[j + 1]);

13.00 14.00

16
New cards

Given below prototype of a function:

void five(double x, double yp, int zp);

Given these variable declarations:

int m, n;

double p, q;

What could be a valid call to function five()?

five(6.2, &p, &n);

17
New cards

When the elements in an array are stored from lowest to highest, the array is sorted in __________ order.

ascending

18
New cards

int square(int); is an example of a function ________.

prototype

19
New cards

What will be the output of this program fragment?

int i;

for(i = 0; i = 1; ++i){

printf("ans1");

printf("ans2");

infinite loop

20
New cards

Which of the following is NOT a correct way to initialize an array?

int n[5] = {0, 7, 0, 3, 8, 2);

21
New cards

What is the output of the following code fragment?

int i;

for(i = 0; i<2; i++){

printf("ans1");

printf("ans2");

ans1ans2ans1ans2

22
New cards

A valid reason for building programs out of functions is:

All of the above

23
New cards

How many times will the following loop iterate?

int k = 1;

while (k<=5){

printf("%d", k);

}

Infinite

24
New cards

What will be the output of this program fragment?

int i = 0;

while (i<3){

printf("\t%d %d", i, 5-i);

i = i+ 1;

}

05 14 23

25
New cards

What is the output of the following code fragment?

int x = 0;

while (x<=3){

printf("%d\t", x + 2);

x++;

}

2 3 4 5

26
New cards

In the fragment below, what is the minimum size of result required for successful and valid concatenation of "double" and "trouble"?

strcpy(result, "double");

strcpy(result, "trouble");

15

27
New cards

What is the value of the expression that follows?

strcmp("dog", "Dog");

1

28
New cards

What is the value of variable "s" after execution of the program fragment below?

char h[6] = "wild";

char p[6] = "crazy";

char s[10];

strcpy(s, h);

strcat(s, p);

"wildcrazy"

29
New cards

_______ may contain different data types.

structures

30
New cards

What does the following function do?

int func(int m, int n){

int ans;

if (n == 0)

ans = m;

else

ans = 1 + func(m, n-1);

return (ans);

}

performs two integer addition

31
New cards

What is the value of the expression that follows?

strcmp("dog", "Dog");

1

32
New cards

Keyword _________ introduces the structure definition.

struct

33
New cards

Which function does NOT read data from standard input?

printf

34
New cards

To test whether a character is one of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, use the _________ standard library function.

isdigit

35
New cards

What does the following function do?

int func(int n){

int ans;

if (n == 1)

ans = 1;

else

ans = n + func(n-1);

return (ans);

Computes (addition of numbers .. (n-1) + n) using a recursive definition.

36
New cards

What will be the output of the following?

#include

void main(){

struct student{

int no;

char name[20];

};

struct student s;

no = 8;

printf("%d", no);

}

Compile time error

37
New cards

What is the right way to access values of structure variable book{price, page}?

printf{"%d %d", book.price, book.page);

38
New cards

What value is return by the following call to strlen?

strlen("robot")

5

39
New cards

Consider the following code fragment: char str[10];

scanf("%s", str);

What will happen if scanf encounters the string "programming" when scanning a value for str?

Function scanf will store the entire string "programming", even though there is insufficient space in str. The string will overflow str.

40
New cards

What will be the output of the following?

#include

struct p {

int k;

char c;

};

int p = 10;

int main(){

struct p x;

x.k = 10;

printf("%d %d\n", x.k, p);

}

10 10

41
New cards

Given the following structure definition:

struct part{

unsigned int partNumber;

char partName[25];

};

Reading the a part number and the a part name from the keyboard into the individual members of a structurepart variable called a.

scanf("%d %24s", &a.partNumber, a.partName);

42
New cards

In C, it is appropriate to say that a string is a(n) ________.

pointer

43
New cards

What will be the output of the following?

#include

struct{

int k;

char c;

};

int main(){

struct p;

p.k = 10;

printf("%d\n", p.k);

}

Compile time error

44
New cards

What does the deck[52] array contain in the following statement?

struct card a, deck[52], *cPtr;

card structure elements

45
New cards

What is the value of the expression that follows?

strcmp("5", "49");

1

46
New cards

What is the output of the following program:

#include

struct Point{

int x, y, z;

};

int main(){

struct Point p1 = {.y = 0, .z = 1, .x = 2};

printf("%d %d %d", p1.x, p1.y, p1.z);

return 0;

}

2 0 1

47
New cards

Consider the following code fragment.

char str[10];

scanf("%s", str);

What will happen if scanf encounters the string "vivaciously" when scanning a value for str?

Function scanf will store the entire string "vivaciously", even though there is insufficient space in str. The string will overflow str.

48
New cards

If the printf function is passed a character array that is not null terminated it will:

print the contents of the character array and keep printing characters in memory until it encounters a null character

49
New cards

Which function returns the length of a string, not including the null terminator?

strlen

50
New cards

What does the following function do?

int c_digits(const char *str){

int ans;

if (str[0] =='\0')

ans = 0;

else

if (isdigit(str[0]))

ans = 1 + count_digits(&str[1]);

else

ans = count_digits(&str[1]);

return (ans);

}

Counts the number of digits in the string str